diff --git a/lib/debug/breakpoint.rb b/lib/debug/breakpoint.rb index 78c4d2174..d7dcd8967 100644 --- a/lib/debug/breakpoint.rb +++ b/lib/debug/breakpoint.rb @@ -189,7 +189,8 @@ def activate iseq, event, line @iseq = iseq @type = event @line = line - @path = iseq.absolute_path + # eval'd sources such as ERB have a path but no absolute path (debug#1129) + @path = iseq.absolute_path || iseq.path @key = [@path, @line].freeze SESSION.rehash_bps diff --git a/test/console/erb_breakpoint_test.rb b/test/console/erb_breakpoint_test.rb new file mode 100644 index 000000000..d90b43f7c --- /dev/null +++ b/test/console/erb_breakpoint_test.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require_relative '../support/console_test_case' + +module DEBUGGER__ + class ErbBreakpointTest < ConsoleTestCase + ERB_PATH = File.expand_path("../../tmp-erb-view/index.html.erb", __dir__) + + def write_temp_file(program) + FileUtils.mkdir_p(File.dirname(ERB_PATH)) + File.write(ERB_PATH, "placeholder") + super + end + + def remove_temp_file + super + FileUtils.rm_f(ERB_PATH) + Dir.rmdir(File.dirname(ERB_PATH)) rescue nil + end + + def program + <<~RUBY + 1| eval(<<~'SRC', binding, #{ERB_PATH.inspect}) + 2| def render + 3| a = 1 + 4| b = a + 1 + 5| b + 6| end + 7| SRC + 8| render + RUBY + end + + def test_breakpoint_on_eval_source_keeps_its_path + debug_code program do + type "b #{ERB_PATH}:3" + type 'c' + assert_line_text(/BP - Line #{Regexp.escape(ERB_PATH)}:3/) + type 'c' + end + end + end +end