# \[ANN\] assert{ 2.0 }

**URL:** <https://www.ruby-forum.com/t/ann-assert-2-0/128850>\
**Category:** Rails\
**Created:** [February 12, 2008, 4:45am UTC](https://www.ruby-forum.com/t/ann-assert-2-0/128850 "2008-02-12T04:45:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [February 12, 2008, 4:45am UTC](https://www.ruby-forum.com/t/ann-assert-2-0/128850/1 "2008-02-12T04:45:25Z")

</div>

Railsers:

The following RubyUnit assertions are now obsolete:

assert  
assert\_block  
assert\_equal  
assert\_instance\_of  
assert\_kind\_of  
assert\_operator  
assert\_match  
assert\_nil  
assert\_no\_match  
assert\_not\_equal  
assert\_not\_nil

The next time you think to type any of them, use assert{ 2.0 } instead.  
Put whatever you like inside the { block }. assert\_equal(x, y) becomes  
assert{ x == y }. assert\_not\_nil(x) becomes … just assert{ x }! If the  
last statement in that block fails, your test runner will reflect the  
name and value of every variable in your assertion. Diagnosing assertion  
failures has never been easier!

Get assert{ 2.0 } the usual way:

gem install assert2

Then require ‘assert2’ into your test suites.

Use deny{} for situations like assert\_nil that must fail.

To provide even more commentary, when either assertion fails, pass a  
string into either assert or deny, like this:

assert(‘my colleague made me do this’){ foo() \< 42 }

Note: This works “best” with Ruby 1.8.6!

Feedback welcome, and happy testing!

–  
Phlip  
[O'Reilly Media - Technology and Business Training](http://www.oreillynet.com/ruby/blog/2008/02/assert2.html)
