There are various versions of the assert_difference assertion floating around out there, and I was surprised when someone pointed out that it wasn't in core yet. The attached patch is a variation of this assertion from http://blog.caboo.se/articles/2006/06/13/a-better-assert_difference. This is a very handy assertion and could be used to clean up a lot of tests, especially the generated tests for scaffold and resource_scaffold.
Old:
def test_should_destroy_account
old_count = Account.count
delete :destroy, :id => 1
assert_equal old_count-1, Account.count
assert_redirected_to accounts_path
end
New:
def test_should_destroy_account
assert_difference(Account, :count) { delete :destroy, :id => 1 }
assert_redirected_to accounts_path
end