GlyphGryph
GlyphGryph

Reputation: 4794

Rspec tags for tests without textual descriptions?

Pretty simple question, but I can't find an answer in the docs. How can I add tags to specific Rspec examples that lack textual descriptions? For example, if you are using the fairly common ":focus" tag to select the tests you want to run (though that's not the only thing I need the tags for), you would, normally, write:

specify "the value should be 2", :focus => true do 
  @value.should be(2) 
end

However, it is not uncommon for simple tests to avoid redundancy to let the test itself do the talking and leave out the "the value should be 2" element, giving you something like:

context "the value" do
  subject{@value}
  it {should be(2)}
  it {should_not be(3)
end

However, I can't figure out how to add tags to that sort of test. Is this possible? Something like:

it :focus {should have_content("Oh yeah")}

Upvotes: 0

Views: 181

Answers (2)

David Chelimsky
David Chelimsky

Reputation: 9000

You were close, but Ruby won't parse it :focus => true { ... }. Try this:

it(:focus => true) { should do_something }

Upvotes: 1

Marnen Laibow-Koser
Marnen Laibow-Koser

Reputation: 6337

Yes, this is possible. Try it! You may need to call subject before you do it {should have_content('Oh yeah')}.

Upvotes: 0

Related Questions