diff --git a/spec/lib/im-lost_spec.rb b/spec/lib/im-lost_spec.rb index 72dda51..9a20832 100644 --- a/spec/lib/im-lost_spec.rb +++ b/spec/lib/im-lost_spec.rb @@ -9,6 +9,9 @@ def initialize @bar = 22 end + def baz = 'baz' + def nix = 'nix' + def add(arg0, arg1) = arg0 + arg1 def add_kw(arg0:, arg1:) = arg0 + arg1 def add_block(arg, &block) = arg + block[] @@ -38,11 +41,22 @@ def fwd(...) = add(...) after { ImLost.untrace_all! } - it 'traces method calls' do - expect { sample.foo + sample.bar }.to write <<~OUTPUT - > TestSample#foo() - > TestSample#bar() - OUTPUT + 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 + it 'traces method calls' do + expect { sample.baz + sample.nix }.to write <<~OUTPUT + > TestSample#baz() + > TestSample#nix() + OUTPUT + end + else + it 'traces method calls' do + expect { sample.foo + sample.bar }.to write <<~OUTPUT + > TestSample#foo() + > TestSample#bar() + OUTPUT + end end it 'includes arguments in call signatures' do @@ -119,8 +133,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 @@ -136,13 +150,26 @@ def fwd(...) = add(...) after { ImLost.untrace_all! } - it 'traces method call results' do - expect { sample.foo + sample.bar }.to write <<~OUTPUT - < TestSample#foo() - = 20 - < TestSample#bar() - = 22 - OUTPUT + 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 + it 'traces method call results' do + expect { sample.baz + sample.nix }.to write <<~OUTPUT + < TestSample#baz() + = "baz" + < TestSample#nix() + = "nix" + OUTPUT + end + else + it 'traces method call results' do + expect { sample.foo + sample.bar }.to write <<~OUTPUT + < TestSample#foo() + = 20 + < TestSample#bar() + = 22 + OUTPUT + end end it 'includes arguments in call signatures' do