From 7e2c13269d49859b6f766dba4a8114bc8e7b5131 Mon Sep 17 00:00:00 2001 From: Mike Blumtritt Date: Tue, 18 Jun 2024 08:37:12 +0200 Subject: [PATCH] Respect bug for Ruby v3.0 in tests --- spec/lib/im-lost_spec.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/spec/lib/im-lost_spec.rb b/spec/lib/im-lost_spec.rb index 72dda51..21dc2c7 100644 --- a/spec/lib/im-lost_spec.rb +++ b/spec/lib/im-lost_spec.rb @@ -1,14 +1,20 @@ # frozen_string_literal: true class TestSample - attr_reader :foo - attr_accessor :bar - def initialize @foo = 20 @bar = 22 end + if RUBY_VERSION.to_f <= 3.0 + # there is a bug in Ruby 3.0 which does not allow to trace + # methods declared with attr_xxx + def foo = @foo + def bar = @bar + else + attr_reader :foo, :bar + end + def add(arg0, arg1) = arg0 + arg1 def add_kw(arg0:, arg1:) = arg0 + arg1 def add_block(arg, &block) = arg + block[] @@ -119,8 +125,8 @@ def fwd(...) = add(...) it 'can include caller locations' do ImLost.caller_locations = true - expect { sample.foo }.to write <<~OUTPUT - > TestSample#foo() + expect { sample.add(1, 1) }.to write <<~OUTPUT + > TestSample#add(1, 1) #{__FILE__}:#{__LINE__ - 2} OUTPUT end @@ -386,7 +392,9 @@ def fwd(...) = add(...) it 'prints local variables' do expect do test = :foo_bar_baz - sample = test.to_s + sample = test + sample = sample.to_s + ImLost.vars(binding) end.to write <<~OUTPUT * #{__FILE__}:#{__LINE__ - 2}