Skip to content

Commit cda23ba

Browse files
committed
Add workaround for ruby 2.2
In ruby 2.2, TracePoint#binding may return nil. Close #10.
1 parent 99122e0 commit cda23ba

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/power_assert.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def initialize(assertion_proc_or_source, assertion_method, source_binding)
118118
target_thread = Thread.current
119119
@trace = TracePoint.new(:return, :c_return) do |tp|
120120
next if method_ids and ! method_ids.include?(tp.method_id)
121+
next unless tp.binding # workaround for ruby 2.2
121122
locs = tp.binding.eval('::Kernel.caller_locations')
122123
current_diff = locs.length - @base_caller_length
123124
target_diff = TARGET_CALLER_DIFF[tp.event]

test/test_power_assert.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,10 @@ def test_assertion_message_with_string
413413
String(a) + String(@b) + String(@@c) + String($d)
414414
END
415415
end
416+
417+
def test_workaround_for_ruby_2_2
418+
assert_nothing_raised do
419+
assertion_message { Thread.new {}.join }
420+
end
421+
end
416422
end

0 commit comments

Comments
 (0)