May 27, 2007
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
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 Comments
May 28, 2007
Try asserting the difference on post.comments.size with the old syntax and you’ll see why it changed ;)
May 28, 2007
Well, I trusted that it was for the best. :) Thanks for the example.
Dec 19, 2007
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.