There are two kinds of developers: those who use should in RSpec examples and those who use present tense.
describe Fridge do
when "plugged in" do
before do
subject.plug!
end
it "should keep food cold" do
subject.temperature.should be between(35).and(38).degrees
end
end
end
describe Fridge do
when "plugged in" do
before do
subject.plug!
end
it "keeps food cold" do
subject.temperature.should be between(35).and(38).degrees
end
end
end
Should you use should?
My short answer is no , you shouldn’t. Write your examples in present tense. Two reasons.
- BDD often refers to examples as documentation. Imagine that your fridge’s documentation said “when plugged in, it should keep food cold”. IMO it should say “when plugged in, it keeps food cold”.
- Using “should” makes the text longer by a few characters. We have over 3000 specs in one projects, probably saving a megabyte worth of test descriptions by not using “should”. Shorter is better.
Thx @mzikherman for heavily contributing to this thought.