Merge pull request #42870 from pedrosnk/pm/import_of_active_support_test_assertions

assert_changes works on including ActiveSupport::Assertions class
This commit is contained in:
Jean Boussier 2021-07-28 15:59:21 +02:00 committed by GitHub
commit 8a22369071
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

@ -189,7 +189,7 @@ def assert_changes(expression, message = nil, from: UNTRACKED, to: UNTRACKED, &b
error = "#{expression.inspect} didn't change"
error = "#{error}. It was already #{to}" if before == to
error = "#{message}.\n#{error}" if message
assert_not_equal before, after, error
refute_equal before, after, error
unless to == UNTRACKED
error = "Expected change to #{to}\n"

@ -200,4 +200,20 @@ def test_stub_any_instance_with_instance
assert_equal instance, Level.new
end
end
def test_assert_changes_when_assertions_are_included
test_unit_class = Class.new(Minitest::Test) do
include ActiveSupport::Testing::Assertions
def test_assert_changes
counter = 1
assert_changes(-> { counter }) do
counter = 2
end
end
end
test_results = test_unit_class.new(:test_assert_changes).run
assert test_results.passed?
end
end