A while back, I wrote a post moaning about RSpec.
My basic point was that there is something that feels wrong about it, and at the time, I couldn’t put my finger on it.
Now I have been using RSpec solidly for a week, on a new project, I think I have it. It’s the syntax.
Everytime I start writing expectations I put my spaces and underscores in the wrong place.
@person.name.should_not be_blank versus @person.name.should not_be blank. The latter is what my fingers think it should be.
I understand that be_XXX is a particular RSpec construct. And should or should_not marks an expectation.
But somewhere in there, the word breaks feel arbitrary and wrong.
In RSpec’s defence, however, there is one advantage that puts it way ahead of Test::Unit.
You see, because of the above, I find RSpec hard to write. I keep getting bits wrong and having to retype lines.
However, when looking back through some Test::Unit code I had written for another project, I came across RSpec’s real advantage. Test::Unit is easy to write but practically impossible to read. I had no idea what was going on, and if a seemingly trivial change caused a cascade of errors, it took ages to root out the problem.
But RSpec is easy to read.
it "should not have a blank name" do
@person.name = ''
@person.should_not be_valid
end
And, ultimately, that means RSpec wins.
Arrgghhh – stupid CSS. Not got time to fix it now – sorry.
This strikes me as the same reason why AppleScript is easy to read but the learning curve is steep due to the English-but-it-isn’t-really-ness of it.
Hi Peter. You’re probably right – I love the idea of Applescript but it has always felt like too much effort to learn. Likewise with RSpec – I liked the idea, but it’s only now that I have been forced to learn it.