Published on
1 min read

Rspec Run specific set of tests using --tag option

Authors

In my current project, I wanted to avoid running a few slow tests every time. The tagging feature in RSpec allows us to filter which examples to run.

You can use the --tag (or -t) option to filter examples. Tags can be simple flags or key:value pairs.

Tagging Examples

describe "group with tagged specs" do
  it "example I'm working on now", :focus => true do; end
  it "special example with string", :type => 'special' do; end
  it "special example with symbol", :type => :special do; end
  it "slow example", :skip => true do; end
  it "ordinary example", :speed => 'slow' do; end
  it "untagged example" do; end
end

Running Tagged Tests

To run only examples with a specific tag (e.g., focus):

rspec spec/ --tag focus

To exclude examples with a specific tag (using ~):

rspec spec/ --tag ~speed:slow

Detailed documentation can be found here.

TwitterLinkedInHacker News