Skip to content

Commit

Permalink
Merge pull request #42870 from pedrosnk/pm/import_of_active_support_t…
Browse files Browse the repository at this point in the history
…est_assertions

assert_changes works on including ActiveSupport::Assertions class
  • Loading branch information
byroot authored and rafaelfranca committed Jul 28, 2021
1 parent d9964f6 commit 9f3dd7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/testing/assertions.rb
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions activesupport/test/testing/method_call_assertions_test.rb
Expand Up @@ -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

0 comments on commit 9f3dd7e

Please sign in to comment.