How to Exclude Rspec tests matching a specific tag

This article describe how to exclude tests matching a specific tag.


Preparation

Please set an option to give us a cleaner syntax: spec/spec_helper.rb

1
2
3
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
end

Adding tag

1
2
3
4
5
describe '#do_something', :skip do
it 'returns something' do
expect(described_class.new.do_something).to eq '...'
end
end

Tag based execution

Run everything, except for :skip tests:

1
$ bundle exec rspec --tag \~skip spec/

If you want to run tests mathcing :skip tag:

1
$ bundle exec rspec --tag skip spec/

Special Thanks