Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force run all RSpec specs ignoring :focus tag

Tags:

rspec

rspec2

Given the following RSpec configuration (v2.12.0):

RSpec.configure do |config|
 config.treat_symbols_as_metadata_keys_with_true_values = true
 config.filter_run :focus => true
 config.run_all_when_everything_filtered = true
end

Sometimes people forget to remove the :focus tag from specs and in a continuous integration environment where we want all specs to be run, only the specs with the leftover :focus tag get run.

I've tried:

rspec --tag ~focus

... which runs all specs excluding those tagged with :focus

Is there a way to force run ALL specs ignoring any tags using rspec's command line options?

like image 555
prashantrajan Avatar asked Feb 18 '13 05:02

prashantrajan


4 Answers

I just added this to a project:

config.before :focused => true do
  fail "Hey dummy, don't commit focused specs." if ENV['FORBID_FOCUSED_SPECS']
end

And in the script that our continuous integration server runs:

export FORBID_FOCUSED_SPECS=true
like image 194
bkeepers Avatar answered Nov 12 '22 11:11

bkeepers


You could remove the lines:

 config.filter_run :focus => true
 config.run_all_when_everything_filtered = true

and tell users to run focused tests with rspec --tag focus. That way the CI will always run the full test suite.

You might consider checking the environment in the configuration block and including/excluding the filter_run setting appropriately.

Another thought: if you are using git, set a pre-commit hook to prevent specs with :focus from creeping into the code base in the first place.

like image 29
zetetic Avatar answered Nov 12 '22 10:11

zetetic


I wanted to automatically fail on our continuous integration server when focus was set. This was rewritten based on code from myronmarston to work correctly with rspec-rails 3.2.0:

  config.before(:example, :focus) do
    fail 'This example was committed with `:focus` and should not have been'
  end if ENV['CI']
like image 41
Dan Kohn Avatar answered Nov 12 '22 10:11

Dan Kohn


Try: rspec --tag focus --tag ~focus

like image 29
dysbulic Avatar answered Nov 12 '22 11:11

dysbulic