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?
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
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.
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']
Try: rspec --tag focus --tag ~focus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With