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
  Post.create_valid
end

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

assert_difference 'Post.count' do
  Post.create_valid
end

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.

3 Responses to “assert_difference has morphed”

  1. DHH Says:

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

  2. John Nunemaker Says:

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

  3. so Says:

    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 :-)

Leave a Reply


(textile enabled)