Elangovan S Elangovan S - 3 months ago 9
Ruby Question

how to run rspec with multiple tags

This is the sample rspec in ruby

require "rspec"
describe "Testing" do
it "test1",:status => "low" do
puts "test1"
expect(true).to eq true
end
it "test2",:status => "high" do
puts "test2"
expect(true).to eq true
end
it "test3",:status => "low" do
puts "test3"
expect(true).to eq true
end
it "test4",:status => "medium" do
puts "test4"
expect(true).to eq true
end
end


This is the command to run the high status test

rspec file_name --tag @status:"high"


Now i want to run high and medium status cases. any idea?

Answer

Filtering by tag uses a hash internally, which means that you can't specify multiple filters for the same key. For instance, if you try to exclude :name => 'foo' and :name => 'bar', you will only end up excluding :name => 'bar'.

Read here.

You have to rename your tags to run multiple examples like this

require "rspec"
describe "Testing" do
  it "test1",low: true do
    puts "test1"
    expect(true).to eq true
  end
  it "test2", high: true do
    puts "test2"
    expect(true).to eq true
  end
  it "test3", low: true do
    puts "test3"
    expect(true).to eq true
  end
  it "test4", medium: true do
    puts "test4"
    expect(true).to eq true
  end
end

And run your test like this:

rspec <file_name> --tag high --tag medium

Or in your case you may just exlude one tag:

rspec <file_name> --tag ~status:low