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 7e2c132
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions spec/lib/im-lost_spec.rb
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 7e2c132

Please sign in to comment.