diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 006d44d4c63e4..b52fd76300a14 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -6,7 +6,7 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner # :nodoc: APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/ - RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/ + RENDER_TEMPLATE_PATTERN = /:in [`'].*_\w+_{2,3}\d+_\d+'/ def initialize super diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 55188ec38cc0b..a3eccff38033b 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -43,6 +43,13 @@ def setup assert_equal "app/views/application/index.html.erb:4", result[0] end + test "#clean should omit ActionView template methods names on Ruby 3.4+" do + method_name = ActionView::Template.new(nil, "app/views/application/index.html.erb", nil, locals: []).send :method_name + backtrace = [ "app/views/application/index.html.erb:4:in 'block in #{method_name}'"] + result = @cleaner.clean(backtrace, :all) + assert_equal "app/views/application/index.html.erb:4", result[0] + end + test "#clean_frame should consider traces from irb lines as User code" do assert_equal "(irb):1", @cleaner.clean_frame("(irb):1") assert_nil @cleaner.clean_frame("/Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'") @@ -67,4 +74,10 @@ def setup frame = @cleaner.clean_frame("app/views/application/index.html.erb:4:in `block in #{method_name}'", :all) assert_equal "app/views/application/index.html.erb:4", frame end + + test "#clean_frame should omit ActionView template methods names on Ruby 3.4+" do + method_name = ActionView::Template.new(nil, "app/views/application/index.html.erb", nil, locals: []).send :method_name + frame = @cleaner.clean_frame("app/views/application/index.html.erb:4:in 'block in #{method_name}'", :all) + assert_equal "app/views/application/index.html.erb:4", frame + end end