Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining RSpec filters?

Tags:

ruby

rspec

I've been looking through the docs, but descriptions of how multiple filters work seem to be a bit lacking. Does anyone have a good explanation or source of a good explanation for the behaviour of multiple filters? Does the order they are listed matter? Here's an example of code that might have behaviour other than what one could expect...

Rspec.configure do |c|
  this_version = get_version_number.to_sym
  c.filter_run :focus=> true
  c.filter_run_excluding :limit_to=>true, this_version => false
  c.filter_run :new_stuff=>true
  c.run_all_when_everything_filtered
end

it "is focused, but not new", :focus
it "is is new", :new_stuff
it "is new and focused", :new_stuff, :focus
it "is focused and new, but limited to a different version", :focus, :limit_to, :correct_version

Experimenting with this, it also seems like multiple arguments on the "filter_run_excluding" line simple act is if you wrote the line multiple times. Is there a way to get it to actually combine the filter checks so that it excludes (or runs, I suppose) only examples that have both the tags listed?

like image 952
GlyphGryph Avatar asked Nov 29 '11 19:11

GlyphGryph


1 Answers

Run multiple filters from the command line with this:

rspec spec --tag my_tag --tag my_second_tag -- tag ~my_third_tag

The ~ will exclude any spec with those tags, so its often useful to do something like

rspec spec --tag ~long_runing
like image 78
Doug Avatar answered Oct 19 '22 23:10

Doug