Friday, February 26, 2010

Ruby: Using "should not" in Cucumber

Cucumber lets you write tests like 'I should not see "such and such"'. Generally, you write the test, watch it fail, write the code, and then watch it pass.

Having used Cucumber for several months, I've been bitten by "should not" several times. It's very easy to misspell something, and the "should not" test will pass even though it shouldn't. I've even seen tests that test for "should not" even though the test should have been removed with the feature they were testing which was long gone. After all, you can write 'I should not see "practically anything"', and it'll almost always pass ;)

My experience is that it's much more robust to do something like:
Given ...
Then I should see "blah"

Given ...
And I reload
Then I should not see "blah"
By using "should see" and "should not see" side-by-side, your test becomes much more robust.

No comments: