Skip to content

Commit

Permalink
Respect bug for Ruby v3.0 in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mblumtritt committed Jun 18, 2024
1 parent fb1560b commit 4c867fa
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions spec/lib/im-lost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4c867fa

Please sign in to comment.