rails/activesupport/lib
Genadi Samokovarov 16f24cd10f 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.

🍻
2016-07-17 12:58:57 +03:00
..
active_support Introduce assert_changes and assert_no_changes 2016-07-17 12:58:57 +03:00
active_support.rb Add compatibility for Ruby 2.4 to_time changes 2016-04-23 15:03:50 +01:00