diff options
author | Genadi Samokovarov <gsamokovarov@gmail.com> | 2016-06-13 23:28:05 +0300 |
---|---|---|
committer | Genadi Samokovarov <gsamokovarov@gmail.com> | 2016-07-17 12:58:57 +0300 |
commit | 16f24cd10ffca6be49e394b9404e9564a94aeeda (patch) | |
tree | 97d400eea871ae3f431fe5a0bdd62fe1d5a2fa2b /.codeclimate.yml | |
parent | 9fcfb86c42d116cd4145b702dd5c73ce1493b5b9 (diff) | |
download | rails-16f24cd10ffca6be49e394b9404e9564a94aeeda.tar.gz rails-16f24cd10ffca6be49e394b9404e9564a94aeeda.tar.bz2 rails-16f24cd10ffca6be49e394b9404e9564a94aeeda.zip |
Introduce `assert_changes` and `assert_no_changes`
Those are assertions that I really do miss from the standard
`ActiveSupport::TestCase`. Think of those as a more general version of
`assert_difference` and `assert_no_difference` (those can be implemented
by assert_changes, should this change be accepted).
Why do we need those? They are useful when you want to check a
side-effect of an operation. `assert_difference` do cover a really
common case, but we `assert_changes` gives us more control. Having a
global error flag? You can test it easily with `assert_changes`. In
fact, you can be really specific about the initial state and the
terminal one.
```ruby
error = Error.new(:bad)
assert_changes -> { Error.current }, from: nil, to: error do
expected_bad_operation
end
```
`assert_changes` follows `assert_difference` and a string can be given
for evaluation as well.
```ruby
error = Error.new(:bad)
assert_changes 'Error.current', from: nil, to: error do
expected_bad_operation
end
```
Check out the test cases if you wanna see more examples.
:beers:
Diffstat (limited to '.codeclimate.yml')
0 files changed, 0 insertions, 0 deletions