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

2

5

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?

Dalliance answered 25/2, 2012 at 16:53 Comment(0)
D
6

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.

Dalliance answered 26/2, 2012 at 18:2 Comment(0)
A
5

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
Athos answered 12/3, 2013 at 15:27 Comment(2)
And in just 6 minutes, it was merged into guard-rspec. Awesome. :)Athos
Today guard tells you: "Guard::RSpec DEPRECATION WARNING: The :exclude option is deprecated. Please Guard ignore method instead. github.com/guard/guard#ignore"Puckery

© 2022 - 2024 — McMap. All rights reserved.