rspec/rspec-core — Issue #470: Run the same spec multiple times w/ different filters
Author: jfelchner
Created: 2011-10-08 15:28:49+00:00
State: open

_Disclaimer: This request specifically stems from doing JavaScript acceptance tests with Capybara. Although I can see use cases for other situations._

All of my applications are coded so that they work fine with JS turned off, but with JS turned _on_, you get a lot of nice bells and whistles to make the user experience more pleasant. Because of this, from the user's point of view, the interactions on most things are identical; however I want to test that it works both w/ and w/o JS.

What I'd like is to be able to do is set some sort of flag to tell RSpec to run the same spec twice w/ each filter set. Something like:

it 'does this same thing with and without JS enabled', :run_with => [{:js => true}, {:js => false}] do
# stuff here
end

I know this can be accomplished with shared examples but the resulting code is not very elegant.

It could additionally be used if you wanted to test w/o JS (Rack test) w/ JS on Firefox (Selenium) and w/ JS on Webkit (capybara-webkit) like this:

it 'does this same thing with and without JS enabled', :run_with => [{:js => false}, {:driver => :selenium}, {:driver => :webkit}] do
# stuff here
end

I'm also envisioning a way to use custom filters to specify the `run_with` options so it's not quite so verbose such as:

it 'does this same thing with and without JS enabled', :run_with_all_drivers => true do
# stuff here
end

Thoughts? I looked through the docs and the code and didn't see a way to currently do this with filters.