assert_difference(expressions, difference = 1, message = nil) {...}
Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.
没看懂文档,谁能给细说一下啊。附上一范例。
test "should create post" do
assert_difference('Post.count') do
post :create, :post => { :title => 'Hi', :body => 'This is my first post.'}
end
assert_redirected_to post_path(assigns(:post))
assert_equal 'Post was successfully created.', flash[:notice]
end
非常感谢。