lib/power_assert/context.rb in power_assert-1.0.1 vs lib/power_assert/context.rb in power_assert-1.0.2

- old
+ new

@@ -21,11 +21,10 @@ trace_alias_method && tp.event == :return ? tp.binding.eval('::Kernel.__callee__') : tp.method_id next if ! method_id_set[method_id] next if tp.event == :c_return and not (@parser.lineno == tp.lineno and @parser.path == tp.path) - next unless tp.binding # workaround for ruby 2.2 locs = PowerAssert.app_caller_locations diff = locs.length - base_caller_length if (tp.event == :c_return && diff == 1 || tp.event == :return && diff <= 2) and Thread.current == @target_thread idx = -(base_caller_length + 1) if @parser.path == locs[idx].path and @parser.lineno == locs[idx].lineno @@ -149,12 +148,14 @@ if PowerAssert.app_context? and Thread.current == @target_thread @trace_call.disable locs = PowerAssert.app_caller_locations path = locs.last.path lineno = locs.last.lineno - line ||= open(path).each_line.drop(lineno - 1).first - @parser = Parser.new(line, path, lineno, @assertion_proc.binding, assertion_method.to_s) + if File.exist?(path) + line ||= open(path).each_line.drop(lineno - 1).first + @parser = Parser.new(line, path, lineno, @assertion_proc.binding, assertion_method.to_s) + end end end end def yield @@ -178,11 +179,15 @@ def initialize(binding) target_frame, *base = PowerAssert.app_caller_locations super(base.length) path = target_frame.path lineno = target_frame.lineno - line = open(path).each_line.drop(lineno - 1).first - @parser = Parser.new(line, path, lineno, binding) + if File.exist?(path) + line = open(path).each_line.drop(lineno - 1).first + @parser = Parser.new(line, path, lineno, binding) + else + @parser = Parser::DUMMY + end end def enable @fired = true @trace_return.enable