diff options
author | lxxxvi <lxxxvi@users.noreply.github.com> | 2018-05-05 14:11:59 +0200 |
---|---|---|
committer | lxxxvi <lxxxvi@users.noreply.github.com> | 2018-05-05 14:11:59 +0200 |
commit | f4f7659acf22f4f37938034bf78673c81c1511b6 (patch) | |
tree | e225d9d7501b0e1a57b57fd83800ba8174229bf4 | |
parent | 42b9e7e50c084e119a679cf155b70b5efc4d36ff (diff) | |
download | rails-f4f7659acf22f4f37938034bf78673c81c1511b6.tar.gz rails-f4f7659acf22f4f37938034bf78673c81c1511b6.tar.bz2 rails-f4f7659acf22f4f37938034bf78673c81c1511b6.zip |
Clearer error message in assert_changes
When `to:` is passed to `assert_changes`, it now prints the well-known `"Expected: x\n Actual: y"` message.
Before, the message only contained the actual value.
-rw-r--r-- | activesupport/lib/active_support/testing/assertions.rb | 4 | ||||
-rw-r--r-- | activesupport/test/test_case_test.rb | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index a891ff616d..6a56da384f 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -176,7 +176,9 @@ module ActiveSupport assert before != after, error unless to == UNTRACKED - error = "#{expression.inspect} didn't change to #{to}" + error = "#{expression.inspect} didn't change to as expected\n" + error = "#{error}Expected: #{to.inspect}\n" + error = "#{error} Actual: #{after.inspect}" error = "#{message}.\n#{error}" if message assert to === after, error end diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 8a1ecb6b33..19901fad99 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -261,7 +261,7 @@ class AssertionsTest < ActiveSupport::TestCase end end - assert_equal "@object.num should 1.\n\"@object.num\" didn't change to 1", error.message + assert_equal "@object.num should 1.\n\"@object.num\" didn't change to as expected\nExpected: 1\n Actual: -1", error.message end def test_assert_no_changes_pass |