Skip to content

Commit

Permalink
Ruby v3.4 stacktrace uses single-quote vs backtick
Browse files Browse the repository at this point in the history
Since this change [1], lines in the stacktrace use an opening
single-quote instead of a backtick to delimit the method name, e.g.

    foo.rb:5:in 'Foo#bar': boom! (RuntimeError)

Instead of:

    foo.rb:5:in `Foo#bar': boom! (RuntimeError)

This commit makes a relevant assertion specific to the current Ruby
version.

This is somewhat similar to the fixes I put in place in #672, although
those were later considerably simplified in #680. Unfortunately I can't
see a way to achieve a similar simpification in this case.

[1]: https://bugs.ruby-lang.org/]issues/16495
  • Loading branch information
voxik authored and floehopper committed Dec 7, 2024
1 parent 52446eb commit 009f348
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/integration/shared_tests.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'test_runner'
require 'execution_point'
require 'mocha/ruby_version'

# rubocop:disable Metrics/ModuleLength
module SharedTests
Expand Down Expand Up @@ -156,6 +157,8 @@ def test_real_object_unsatisfied_expectation
end

def test_real_object_expectation_does_not_leak_into_subsequent_test
opening_quote = Mocha::RUBY_V34_PLUS ? "'" : '`'

execution_point = nil
klass = Class.new
test_result = run_as_tests(
Expand All @@ -170,7 +173,7 @@ def test_real_object_expectation_does_not_leak_into_subsequent_test
assert_errored(test_result)
exception = test_result.errors.first.exception
assert_equal execution_point, ExecutionPoint.new(exception.backtrace)
assert_match(/undefined method `foo'/, exception.message)
assert_match(/undefined method #{opening_quote}foo'/, exception.message)
end

def test_leaky_mock
Expand Down

0 comments on commit 009f348

Please sign in to comment.