Why it "passes" is bad spec name

In this post I’ll try to explain why you should avoid naming your RSpec scenarios like

  • it "does something"
  • it "works"
  • it "passes"
  • it "fails"
  • it "does not fail"

I saw such specs quite often and admittedly written some myself until I figured out how to fix this code smell.

What exactly is wrong with such specs?

It is repetitive.

It is attempting to document the obvious.

It is like a Filler word which doesn’t provide value in specs.

I guess it could be coming from the official rspec-core documentation which 1.5k+ instances of it “with some messages” examples and just one without a custom message. It could also be coming from other books and blog posts where each spec covers very specific scenario and contain some meaningful information in scenario declaration. But your spec could be too simple or too self-explanatory that it doesn’t need to have its own name.

Another reason why I think it could be so wide spread is because it blocks(not specify or example) are the most popular writing RSpec specs. It is, in fact, the primary API to define a code example accordingly to the source code of rspec-core. When you attempt to describe the behavior or your system starting with the word it you always include some words, even if it’s just it "does something", it "works".

What’s the alternative?

Use example instead of it!

example in many cases better conveys the meaning of your specs because what you’re writing are examples.

example without custom explanation message doesn’t look as bad as it.

example do
  expect(described_class.new('input1').process).to eq('value2')

  expect { described_class.new('invalid input').process }.to raise_error