Guard rspec doesn't run specs - ruby-on-rails

When spec or model changed, guard with options spring rspec shows next output:
04:54:44 - INFO - Running: spec/models/identity_spec.rb
Version: 1.1.2
Usage: spring COMMAND [ARGS]
Commands for spring itself:
binstub Generate spring based binstubs. Use --all to generate a binstub for all known commands.
help Print available commands.
status Show current status.
stop Stop all spring processes for this project.
Commands for your application:
rails Run a rails command. The following sub commands will use spring: console, runner, generate, destroy.
rake Runs the rake command
Frame number: 0/0
I'm using ruby '2.1.0' and 'rails', '4.1.0.rc1' with spring. So, it looks like it doesn't run anything. I tried different cmd options.
guard :rspec do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
end
This throws en error:
05:04:08 - INFO - Running: spec/models/identity_spec.rb
05:04:08 - ERROR - Guard::RSpec failed to achieve its <run_on_modifications>, exception was:
> [#] NoMethodError: undefined method `parse_options' for #<RSpec::Core::ConfigurationOptions:0x007fad670937a8 #args=[]>
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:33:in `_rspec_formatters'
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:29:in `_visual_formatter'
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:21:in `_parts'
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:14:in `initialize'
Full content there with spec helper
I've tried all different variations of options rspec, spring rspec spec and other possible including without any, but had the same result.
rspec spec without guard works fine.
I found similar problem, but it works without spring.

try using
guard 'rspec', :cli => '--drb' do
#your code
end
once I wrote this quick guild for my reference, see if that works for you
HIH

Found the problem. In guard-rspec/guard-rspec.gemspec from 4.2.2 version, line:
s.add_dependency 'rspec', '>= 2.14', '< 4.0'
Conflicted with beta version i guess. So i changed it on next:
s.add_dependency 'rspec', '>= 2.14', '~> 3.0.0.beta2', '< 4.0'
And it works!
And by the way, option spring in cmd caused test to do nothing. So, works this:
guard :rspec, cmd: 'rspec -f doc --color --require spec_helper ' do
And just guard :rspec do, and it consider options from .rspec file, in which i wasn't sure.

Related

After a Capybara failed scenario output screen shot

I want to output a screen shot of the page after a failed scenario.
I'm using capybara, rspec and launchy - my gemfile has
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
gem 'launchy'
end
I've seen various suggestions which include the following code
After do |scenario|
save_and_open_page if scenario.failed?
end
So, I've created a spec\support\env.rb file into which I've put this code (and that is all, there is nothing else in that file). Now when I run
bundle exec rspec
I get
C:/Working/x/spec/support/env.rb:1:in `<top (required)>': undefined method `After' for main:Object (NoMethodError)
If I comment out the lines in env.rb, then the tests run as I'd expect.
What am I missing?
Thanks
Versions:
rails 4
rspec 2.14.1
capybara 2.1.0
launchy 2.3.0
Try wrapping it in a Rspec.configure block, something like:
RSpec.configure do |config|
config.after { |example_group| save_and_open_page if example_group.exception }
end
#ejosafat - extra "example." in you answer, so I used it as following:
RSpec.configure do |config|
config.after { |example_group| save_and_open_page if example_group.exception }
end
There is a gem, you just need to add this to your Gemfile:
gem 'capybara-screenshot', :group => :test
All the instructions can be found here:- https://github.com/mattheworiordan/capybara-screenshot

Issue with guard and ruby versions

I have added guard along with rb-notify to my Gemfile and run bundle:
gem 'guard-rspec', '1.2.1', :group => :test
gem 'rb-inotify', '0.8.8', :group => [:development, :test]
gem 'libnotify', '0.5.9', :group => [:development, :test]
However when I run bundle exec spork I get the following:
bundle exec guard
10:47:09 - INFO - Guard uses Libnotify to send notifications.
10:47:09 - INFO - Guard uses TerminalTitle to send notifications.
10:47:09 - INFO - Guard is now watching at '/home/paul/work/test-demo'
10:47:09 - INFO - Guard::RSpec is running, with RSpec 2!
10:47:09 - INFO - Running all specs
Running tests with args ["--drb", "-f", "progress", "-r", "/home/paul/.rvm/gems/ruby-1.9.2-p290#test-demo/gems/guard-rspec-1.2.1/lib/guard/rspec/formatters/notification_rspec.rb", "-f", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--failure-exit-code", "2", "spec"]...
Done.
/home/paul/.rvm/gems/ruby-1.9.2-p290#test-demo/gems/ffi-1.1.5/lib/ffi_c.so: [BUG] Segmentation fault
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
Aborted
I'm guessing its something with 1.8.7 and 1.9.2. I'm running rvm and 1.9.2. ruby -v tells me 1.9.2 and yet the seg fault seems to be 1.8.7 related.
My guard File is pretty simple:
guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"]
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
Any ideas where I could be going wrong?
EDIT: Weirdly, when i change to use Ruby 1.8.7 it works (after changing a lot of other gems/code that relied on 1.9.2). I'd still like to use a later version of ruby though

Is there a way to configure guard to not run request specs?

I'm using guard to run all my rails specs and its awesome. I've written a bunch of request specs that use capybara and selenium to test my pages javascripts by opening firefox and they are awesome as well however they tend to be slow and pull focus away from my editor while I'm typing.
Is there a way to configure guard to not run my request specs when it runs all and maybe asign a hot key to just run the request specs?
Answering my own question incase other come across this:
rspec-rails can pass command line arguments to rspec via :cli. Additionally examples can be tagged in spec files and then rspec can be run to include or exclude those tagged examples.
Turns out I'm already tagging the examples I wanted to exclude with :js=>true, wich is how you get Selenium to fire up firefox.
describe "Post" do
it "should be able to edit a post", :js=>true do
# your test here
end
end
I made two groups in my Guardfile one for none-javascript specs with :cli => "-t ~js" and another for spec that test javascript with :cli => "-t js". I also passed in the :all_after_pass => false for the javascript group.
here is my new guard file:
group 'none-javascript specs' do
guard 'rspec', :version => 2, :cli => '-r rspec/instafail -f RSpec::Instafail -t ~js' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.jbuilder)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
end
group 'javascript specs' do
guard 'rspec', :version => 2, :all_after_pass => false, :cli => '-r rspec/instafail -f RSpec::Instafail -t js' do
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
watch(%r{^spec/requests/.+_spec\.rb$})
end
end
Now when I start up guard or hit return in the guard term both groups are run executing all specs.
Guard::RSpec is running, with RSpec 2!
Running all specs
Run options: exclude {:js=>true}
...
Finished in 75.78 seconds
428 examples, 0 failures, 1 pending
Guard::RSpec is running, with RSpec 2!
Running all specs
Run options: include {:js=>true}
...
Finished in 63.68 seconds
22 examples, 0 failures
After all test pass only the none-javascript examples are run.
There's an exclude option for guard-rspec. It was implemented in #23, but wasn't documented in the README. I've made a pull request to document that.
Example
guard 'rspec', :exclude => "spec/foo/**/*" # exclude files based on glob

Why libnotify stopped showing Rspec notifications?

I don't know why libnotify stoped showing informations about finished tests.
It shows Spork message: "Rspec successfully started." But after that does not show anything. I`m using Ubuntu.
guard 'spork', :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('spec/spec_helper.rb')
watch(%r{^spec/support/.+\.rb$})
end
guard 'rspec', :version => 2, :cli => "--drb", :all_on_start => false, :all_after_pass => false do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch('spec/acceptance/acceptance_helper.rb') { "spec" }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
# watch(%r{^spec/support/(requests|controllers|mailers|models)_helpers\.rb}) { |m| "spec/#{m[1]}" }
# watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
end
My spec_helper: ***
When I initialize guard:
Running tests with args ["--color", "--format", "progress", "--format", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--require", "/home/rege/.rvm/gems/ruby-1.9.2-p290/gems/guard-rspec-0.5.10/lib/guard/rspec/formatters/notification_rspec.rb", "spec"]...
How to diagnose where is the problem?
EDIT:
Solution: https://github.com/guard/guard-rspec/issues/90#issuecomment-3435651
I had this problem as well and installed the guard-spork (https://github.com/guard/guard-spork) gem (added it to my rails Gemfile and bundle installed). Then, per the instructions on that page, I ran 'guard init spork' which adds a 'spork' section to your Guardfile for files you can watch.
When i ran bundle exec guard, it actually makes sure spork is also started and presto! my test file changes were getting run and the results posted to the notifier. For the record, I use Ubuntu 11.10 64bit with ruby rvm. The relevant gems in my Gemfile were gem 'guard-rspec', gem 'guard-spork', gem 'rspec-rails', gem 'watchr', gem 'spork', gem 'libnotify'. Not sure if all are relevant.
You can find the step by step I used for this in Hartl's awesome Rails tutorial http://ruby.railstutorial.org/chapters/static-pages#sec:guard (sections 3.6.2 and 3.6.3).

rspec failures out of nowhere

Out of no where rspecs started failing with errors like:
ruby 1.8.7, rails 3.06.
~/.rvm/rubies/ree-1.8.7-2011.03/bin/ruby -S bundle exec rspec spec/controllers/gift_cards_controller_spec.rb:30
No DRb server is running. Running in local process instead ...
Run filtered including {:line_number=>30}
F
Failures:
1) GiftCardsController POST to :create for a logged-in User with valid attributes
Failure/Error: it { should respond_with(:redirect) }
NoMethodError:
undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0x11af4324>
# ./spec/controllers/gift_cards_controller_spec.rb:30
Finished in 0.93776 seconds
1 example, 1 failure
Isn't #repond_with a Shoulda matcher? Make sure that it comes after RSpec in your Gemfile:
group :development, :test do
gem 'rspec-rails', '2.4.1'
gem 'shoulda-matchers', '1.0.0.beta1'
end
Having this error after upgrade my old rails app to rails 5.0. then add the following configuration into spec_helper.rb and now its working fine.
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end

Resources