Issue with guard and ruby versions - ruby-on-rails

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

Related

No DRb server is running. Running in local process instead ...(Rails 4/Zeus/guard/rspec 3)

I have just switched from using Spork with Guard to using Zeus
I used this step by step guide: http://blog.blenderbox.com/2014/04/10/testing-rails-3-with-guard-and-zeus/
The thing, is now my routine is
in a terminal window do $ zeus start
in another terminal window: guard
in another window : $rspec
My tests are working fine but I'm very surprised that rspec test suite has gotten slower than with Spork as most people say it's a huge boost in test speed.
What also makes me really think there's a bug is that when I type rspec, it displays a message reading what's below before running tests:
No DRb server is running. Running in local process instead
Somebody got an idea what's the problem ?
thanks
guardfile
require 'active_support/core_ext'
require 'active_support/inflector'
# NEw ZEUS guard
# source - blog.blenderbox.com/2014/04/10/testing-rails-3-with-guard-and-zeus/
guard 'zeus-client', :all_on_start => false, :all_after_pass => false do
ignore %r{^\.zeus\.sock$}
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 features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
guard 'rails-assets', :run_on => [:start, :change] do
watch(%r{^app/assets/.+$})
watch('config/application.rb')
end
You may have the --drb option set in your .rspec file. Delete that line.

Guard rspec doesn't run specs

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.

How can we disable a guard gem in Guardfile

I have more than three guard gems in my Guardfile. When I run guard, I want a specific guard gem is to be disabled, without removing it from Guardfile. How should I disable it?
My next question is, rspec stops running test when it finds a first error. Is there any way to run all rspec errors at a time.
What are the guard gems are essential and easy to implement?
My Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'migrate' do
watch(%r{^db/migrate/(\d+).+\.rb})
watch('db/seeds.rb')
end
guard :annotate do
watch( 'db/schema.rb' )
# Uncomment the following line if you also want to run annotate anytime
# a model file changes
watch( 'app/models/*.rb' )
# Uncomment the following line if you are running routes annotation
# with the ":routes => true" option
watch( 'config/routes.rb' )
end
guard :bundler do
watch('Gemfile')
# Uncomment next line if your Gemfile contains the `gemspec' command.
# watch(/^.+\.gemspec/)
end
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/(.*)(\.erb|\.haml|\.slim)$}) { |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 features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
guard :rubocop do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end
### Guard::Sidekiq
# available options:
# - :verbose
# - :queue (defaults to "default") can be an array
# - :concurrency (defaults to 1)
# - :timeout
# - :environment (corresponds to RAILS_ENV for the Sidekiq worker)
guard 'sidekiq', :environment => 'development' do
watch(%r{^workers/(.+)\.rb$})
end
guard 'rails' do
watch('Gemfile.lock')
watch(%r{^(config|lib)/.*})
end
# Sample guardfile block for Guard::Haml
# You can use some options to change guard-haml configuration
# output: 'public' set output directory for compiled files
# input: 'src' set input directory with haml files
# run_at_start: true compile files when guard starts
# notifications: true send notifictions to Growl/libnotify/Notifu
# haml_options: { ugly: true } pass options to the Haml engine
guard 'puma' do
watch('Gemfile.lock')
watch(%r{^config|lib|api/.*})
end
guard 'rake', :task => 'build' do
watch(%r{^my_file.rb})
end
Group your Guard plugins into groups. This allows you to select a specific group from the command line or switch them at runtime using the scope interactor command.

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).

Resources