Merge pull request #44811 from pjambet/pj/improve-assert-changes-error-message

Improve default message for assert_changes
This commit is contained in:
Eileen M. Uchitelle 2022-04-01 08:49:18 -04:00 committed by GitHub
commit b97c308f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -179,7 +179,7 @@ module ActiveSupport
retval = _assert_nothing_raised_or_warn("assert_changes", &block)
unless from == UNTRACKED
error = "Expected change from #{from.inspect}"
error = "Expected change from #{from.inspect}, got #{before}"
error = "#{message}.\n#{error}" if message
assert from === before, error
end
@ -192,7 +192,7 @@ module ActiveSupport
refute_equal before, after, error
unless to == UNTRACKED
error = "Expected change to #{to}\n"
error = "Expected change to #{to}, got #{after}\n"
error = "#{message}.\n#{error}" if message
assert to === after, error
end

View File

@ -192,7 +192,8 @@ class AssertionsTest < ActiveSupport::TestCase
@object.increment
end
end
assert_equal "Expected change from nil", error.message
assert_equal "Expected change from nil, got 0", error.message
end
def test_assert_changes_with_to_option
@ -277,7 +278,7 @@ class AssertionsTest < ActiveSupport::TestCase
end
end
assert_equal "@object.num should be 1.\nExpected change to 1\n", error.message
assert_equal "@object.num should be 1.\nExpected change to 1, got -1\n", error.message
end
def test_assert_no_changes_pass