Skip to content

Commit

Permalink
Fix inspect format for Ruby >= 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Sep 16, 2024
1 parent bf693fd commit 507a965
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def format_trace(args)
def monotonic_clock
::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
end

def inspect_method_name_for(klass_name, method_name)
if RUBY_VERSION < '3.4.0'
"`#{method_name}'"
else
"'#{klass_name}##{method_name}'"
end
end
end

class MiniTest::Test
Expand Down
5 changes: 3 additions & 2 deletions test/test_fiber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,16 +619,17 @@ def test_inspect
f = spin(:baz) { :foo }

expected = format(
'#<Fiber baz:%s %s:%d:in `test_inspect\' (runnable)>',
"#<Fiber baz:%s %s:%d:in #{inspect_method_name_for(self.class.name, __method__.to_s)} (runnable)>",
f.object_id,
__FILE__,
spin_line_no
)
assert_equal expected, f.inspect

f.await

expected = format(
'#<Fiber baz:%s %s:%d:in `test_inspect\' (dead)>',
"#<Fiber baz:%s %s:%d:in #{inspect_method_name_for(self.class.name, __method__.to_s)} (dead)>",
f.object_id,
__FILE__,
spin_line_no
Expand Down
2 changes: 1 addition & 1 deletion test/test_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_that_suspend_returns_immediately_if_no_watchers
Thread.backend.trace_proc = proc {|*r| records << r }
suspend
assert_equal [
[:block, Fiber.current, ["#{__FILE__}:#{__LINE__ - 2}:in `test_that_suspend_returns_immediately_if_no_watchers'"] + caller]
[:block, Fiber.current, ["#{__FILE__}:#{__LINE__ - 2}:in #{inspect_method_name_for(self.class.name, __method__.to_s)}"] + caller]
], records
ensure
Thread.backend.trace_proc = nil
Expand Down

0 comments on commit 507a965

Please sign in to comment.