Skip to content

Commit

Permalink
Merge pull request #51590 from jhawthorn/backtrace_cleaner_3_4
Browse files Browse the repository at this point in the history
Fix ActionView backtrace filtering on Ruby 3.4+
  • Loading branch information
jhawthorn committed Apr 22, 2024
2 parents c05608b + 3cf6122 commit 734719d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion railties/lib/rails/backtrace_cleaner.rb
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions railties/test/backtrace_cleaner_test.rb
Expand Up @@ -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'")
Expand All @@ -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

0 comments on commit 734719d

Please sign in to comment.