Get real with your specs, punk
In my rspec spec definitions I was finding myself constantly repeating the word “should”.
Like:
it "should add two numbers together"
it "should taste like bananas"
And it's not just me that does this, the standard rspec rails generators have “should” in them too:
it "should create a new instance given valid attributes" do
Banana.create!(@valid_attributes)
end
This irritated me, why can't rspec be like shoulda and include the word “should” in the actual spec definition like this:
should "taste like bananas"
I asked my Twitter followers what I should do, and Joe Martinez responded:
Should is just noise! Eureka!
Jon Larkowski from Hashrocket gave a talk at The Scottish Ruby Conference about some of the more idiosynchratic aspects of RSpec, and sure enough in his examples there weren't any sign of “should” in the examples. (Read it here)
So, now my specs look like this:
it "smells like bananas"
it "adds two numbers together"
This just feels better – more decisive somehow. As my colleague Andrew Donaldson said:
“Gives a rough manly edge to your specs, Clint Eastwood would never say 'should'”.
So, in order to remove the unnecessary shoulds from my specs I came up with this RSpec formatter:
This produces a list of your specs that include the word “should”.
So be like Clint, and be decisive with your specs, Punk