From f6ffdcfcff1979d65812a1eeb9e907ad4a0aa468 Mon Sep 17 00:00:00 2001 From: Pedro Medeiros Date: Sun, 25 Jul 2021 14:18:01 -0400 Subject: [PATCH] assert_changes works on including Assertions class assert_not_equal is an alias for refute_equal that is defined only on the class ActiveSupport::TestCase. This commit ensures ActiveSupport::Testing::Assertions#assert_changes doesn't depends on ActiveSupport::TestCase to work. --- .../lib/active_support/testing/assertions.rb | 2 +- .../test/testing/method_call_assertions_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index dbf435292b..63344d00cb 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -189,7 +189,7 @@ module ActiveSupport 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" diff --git a/activesupport/test/testing/method_call_assertions_test.rb b/activesupport/test/testing/method_call_assertions_test.rb index ba1d55021a..e75630d2e4 100644 --- a/activesupport/test/testing/method_call_assertions_test.rb +++ b/activesupport/test/testing/method_call_assertions_test.rb @@ -200,4 +200,20 @@ class MethodCallAssertionsTest < ActiveSupport::TestCase 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