mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #31011 from danielma/dma/assert-changes-with-to-should-still-assert-change
`assert_changes` should always assert some change
This commit is contained in:
commit
cb86b95b60
3 changed files with 24 additions and 6 deletions
|
@ -1,3 +1,8 @@
|
|||
* `assert_changes` will always assert that the expression changes,
|
||||
regardless of `from:` and `to:` argument combinations.
|
||||
|
||||
*Daniel Ma*
|
||||
|
||||
* Allow the hash function used to generate non-sensitive digests, such as the
|
||||
ETag header, to be specified with `config.active_support.hash_digest_class`.
|
||||
|
||||
|
@ -5,6 +10,7 @@
|
|||
|
||||
*Dmitri Dolguikh*
|
||||
|
||||
|
||||
## Rails 5.2.0.beta2 (November 28, 2017) ##
|
||||
|
||||
* No changes.
|
||||
|
|
|
@ -156,11 +156,12 @@ module ActiveSupport
|
|||
|
||||
after = exp.call
|
||||
|
||||
if to == UNTRACKED
|
||||
error = "#{expression.inspect} didn't change"
|
||||
error = "#{error}. It was already #{to}" if before == to
|
||||
error = "#{message}.\n#{error}" if message
|
||||
assert before != after, error
|
||||
else
|
||||
|
||||
unless to == UNTRACKED
|
||||
error = "#{expression.inspect} didn't change to #{to}"
|
||||
error = "#{message}.\n#{error}" if message
|
||||
assert to === after, error
|
||||
|
|
|
@ -156,6 +156,16 @@ class AssertDifferenceTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_assert_changes_with_to_option_but_no_change_has_special_message
|
||||
error = assert_raises Minitest::Assertion do
|
||||
assert_changes "@object.num", to: 0 do
|
||||
# no changes
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal "\"@object.num\" didn't change. It was already 0", error.message
|
||||
end
|
||||
|
||||
def test_assert_changes_with_wrong_to_option
|
||||
assert_raises Minitest::Assertion do
|
||||
assert_changes "@object.num", to: 2 do
|
||||
|
@ -218,6 +228,7 @@ class AssertDifferenceTest < ActiveSupport::TestCase
|
|||
def test_assert_changes_with_message
|
||||
error = assert_raises Minitest::Assertion do
|
||||
assert_changes "@object.num", "@object.num should 1", to: 1 do
|
||||
@object.decrement
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue