test-unit / test-unit-activesupport

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

NoMethodError: undefined method `error' for Test::Unit::AssertionFailedError #17

Closed arika closed 1 hour ago

arika commented 2 hours ago

When an exception is raised in assert_difference or similar methods, test-unit-activesupport raises a NoMethodError.

sample code:

require "test/unit/active_support"
require "stringio"

class TestAssertions < ActiveSupport::TestCase
  setup do
    @logdev = StringIO.new
    self.tagged_logger = ActiveSupport::TaggedLogging.new(Logger.new(@logdev))
  end

  test "NoMethodError" do
    x = 1
    assert_difference("x") { raise }
  ensure
    pp @logdev.string
  end
end

result:

$ ruby -v t.rb
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin24]
t.rb:11: warning: assigned but unused variable - x
Loaded suite t
Started
""
E
==================================================================================================================================
Error: test: NoMethodError(TestAssertions): NoMethodError: undefined method `error' for an instance of Test::Unit::AssertionFailedError
/.../gems/test-unit-activesupport-1.1.1/lib/test/unit/active_support.rb:96:in `rescue in _assert_nothing_raised_or_warn'
/.../test-unit-activesupport-1.1.1/lib/test/unit/active_support.rb:91:in `_assert_nothing_raised_or_warn'
/.../activesupport-7.2.1/lib/active_support/testing/assertions.rb:117:in `assert_difference'
t.rb:12:in `block in <class:TestAssertions>'
==================================================================================================================================
Finished in 0.005774 seconds.
----------------------------------------------------------------------------------------------------------------------------------
1 tests, 1 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
----------------------------------------------------------------------------------------------------------------------------------
173.19 tests/s, 173.19 assertions/s
kou commented 1 hour ago

Thanks. I've fixed it and released a new version.