Testing with Wrong

Years ago I added a testing library to Harvest called assert2. I really loved the syntax, and the test error output was miles ahead of what you get with default Test::Unit output. Here was an example of a simple library providing tons of value.

Over time assert2 died on the vine. Its mantle was picked up by another team, however, and Wrong was born. Wrong uses the same syntax as assert2, but has the added benefit of being actively developed. And the maintainers are responsive. Double bonus!

Nothing to see here when Wrong detects right:

> def slap!(person); person[:attitude] = 'aghast'; end

> joffrey = {:attitude => 'smug'}
> slap!(joffrey)
> assert{ 'aghast' == joffrey[:attitude] }
==> nil  # Test success!

Someone comes along and edits the method, introducing a blatant bug. Luckily there are tests:

> def slap!(person); person[:attitude] = 'humbled'; end

> slap!(joffrey)
> assert{ 'aghast' == joffrey[:attitude] }
==>
 Wrong::Assert::AssertionFailedError: Expected ("aghast" == joffrey[:attitude]),
 but Strings differ at position 0:
 first: "aghast"
 second: "humbled"
 joffrey[:attitude] is "humbled"
 joffrey is {:attitude=>"humbled"}

Objects are blown out and the details are right there in front of you. This makes solving many test failures a matter of looking at the details of your objects, rather than re-re-rerunning your tests with various puts statements. This simple example barely touches on the awesome object details Wrong will display during test failures. Big win.

The syntax is dead simple as well: assert{ thing-you-think-should-be-true }. No messing with a multitude of different method names (assert, assert_nil, assert_equal, etc).

This is how we use Wrong at Harvest. You should start using Wrong as well. Your flow will thank you for it.