Last active
August 29, 2015 14:12
-
-
Save rocLv/50b83fa9024e70db88cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```ruby | |
assert_no_difference 'User.count' do | |
post users_path, user: { name: "", | |
email: "user@invalid", | |
password: "foo", | |
password_confirmation: "bar" } | |
end | |
``` | |
Here we’ve included the params[:user] hash expected by User.new in the create action (Listing 7.24). By wrapping the post in the assert_no_difference method with the string argument ’User.count’, we arrange for a comparison between User.count before and after the contents of the assert_no_difference block. This is equivalent to recording the user count, posting the data, and verifying that the count is the same: | |
```ruby | |
before_count = User.count | |
post users_path, ... | |
after_count = User.count | |
assert_equal before_count, after_count | |
``` | |
Although the two are equivalent, using assert_no_difference is cleaner and is more idiomatically correct Ruby. | |
Author
rocLv
commented
Dec 30, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment