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.
This commit is contained in:
lxxxvi 2018-05-05 14:11:59 +02:00
parent 42b9e7e50c
commit f4f7659acf
2 changed files with 4 additions and 2 deletions

@ -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

@ -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