test-unit / test-unit-activesupport

ActiveSupport adapter for test-unit 3.
GNU Lesser General Public License v2.1
5 stars 5 forks source link

Prevent NameError on activesupport >= 6.1 #14

Closed hoshi-sano closed 2 years ago

hoshi-sano commented 2 years ago

When unexpeced exceptions are raised in test case, ActiveSupport::Testing::Assertions use:


reproduction code

require "test/unit/active_support"

class TestAssertions < ActiveSupport::TestCase
  test "unexpected error" do
    x = 1
    assert_difference("x") { raise }
  end
end

no require "minitest":

Error: test: unexpected error(TestAssertions): NameError: uninitialized constant ActiveSupport::Testing::Assertions::Minitest
/usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/testing/assertions.rb:251:in `rescue in _assert_nothing_raised_or_warn'
/usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/testing/assertions.rb:249:in `_assert_nothing_raised_or_warn'
/usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/testing/assertions.rb:102:in `assert_difference'
test.rb:7:in `block in <class:TestAssertions>'

no include ActiveSupport::Testing::TaggedLogging:


Error: test: unexpected error(TestAssertions): NameError: undefined local variable or method `tagged_logger' for #<TestAssertions:0x00005641cf790f88 @method_name="test: unexpected error", ...(snip)... >
/usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/testing/assertions.rb:252:in `rescue in _assert_nothing_raised_or_warn'
/usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/testing/assertions.rb:249:in `_assert_nothing_raised_or_warn'
/usr/local/bundle/gems/activesupport-7.0.2.2/lib/active_support/testing/assertions.rb:102:in `assert_difference'
test.rb:7:in `block in <class:TestAssertions>'
kou commented 2 years ago

Thanks for your report!

But we should not use classes from minitest. I've pushed a fix for this case by using test-unit features directly instead of using classes from minitest.

hoshi-sano commented 2 years ago

I've checked your commits. Thanks for quick response!