From f4f7659acf22f4f37938034bf78673c81c1511b6 Mon Sep 17 00:00:00 2001 From: lxxxvi Date: Sat, 5 May 2018 14:11:59 +0200 Subject: [PATCH] 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. --- activesupport/lib/active_support/testing/assertions.rb | 4 +++- 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 @@ def assert_changes(expression, message = nil, from: UNTRACKED, to: UNTRACKED, &b 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 @@ def test_assert_changes_with_message 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