Wrong 0.6.0 released

New with this version:

  • “eventually” method for async polling assertions
  • “d” takes an optional message

Full docs in the README at GitHub - sconover/wrong: Wrong provides a general assert method that takes a predicate block. Assertion failure messages are rich in detail.


Wrong provides a simple assert method that takes a block, and
understands
the code inside it, providing verbose failure messages for free.

require “wrong”
include Wrong

assert { 1 == 1 }
#=> nil

assert { 2 == 1 }
#=> Expected (2 == 1), but 2 is not equal to 1

There are also some helper methods:

“rescuing” for catching exceptions:

assert{ rescuing{raise “vanilla”}.message == “chocolate” }

“capturing” for stdout/stderr:

assert { capturing { puts “hi” } == “hi\n” }
assert { capturing(:stderr) { $stderr.puts “hi” } == “hi\n” }

“d” for debugging:

x = 7
d { x } # => prints “x is 7” to the console
d { x * 2 } # => prints “(x * 2) is 14” to the console
d(“math is hard”) { 2 + 2 } #=> prints “math is hard: (2 + 2) is 4”

“close_to?” for floating point comparison

assert { 5.0.close_to?(5.0001) } # default tolerance = 0.001
assert { 5.0.close_to?(5.1, 0.5) } # optional tolerance parameter

“eventually” for async polling:

eventually { night? }

calls night? N times a second, returning the first time it’s true(ish),
or raising an error after M seconds
(default N=4 and M=5)

Alex C. - [email protected] - http://alexch.github.com
Stalk me: Redirecting... | http://twitter.com/alexch |
http://alexch.tumblr.com