May 27, 2007

Posted by John

Tagged testing

Older: My Must Read Summary of RailsConf 2007

Newer: Even Edgier Than Edge Rails

assert_difference has morphed

This is just a little note that assert_difference, the ultimate test helper, has been merged into core. The only issue is that it has changed a bit from the version that I have used. I always used something along the lines of:

assert_difference Post, :count do

The version that got merged into core instead accepts a string like so:

assert_difference 'Post.count' do

Not sure why the syntax is different but that is neither here nor there for me. The only down side is I had to go through all my tests and fix the incorrect arguments. Just thought I would say something here so others know what is going wrong when all their tests fail after upgrading to edge.


  1. Try asserting the difference on post.comments.size with the old syntax and you’ll see why it changed ;)

  2. Well, I trusted that it was for the best. :) Thanks for the example.

  3. I’m using Rails 2.0.1 and the ‘Post.count’ syntax doesn’t seem to be working. I get TypeError: nil is not a symbol. The old syntax works though :-)

Sorry, comments are closed for this article to ease the burden of pruning spam.


Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.


Release your software more often with fewer problems.
Flip your features.