Skip to content

Commit 3e816bf

Browse files
committed
Fixes tests with nested exception backtraces on Ruby master
Ruby master did the following changes (and probably more) https://bugs.ruby-lang.org/issues/16495 https://bugs.ruby-lang.org/issues/20275
1 parent 5ef7f73 commit 3e816bf

File tree

1 file changed

+82
-33
lines changed

1 file changed

+82
-33
lines changed

actionpack/test/dispatch/debug_exceptions_test.rb

Lines changed: 82 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,26 @@ def method_that_raises
4545
end
4646

4747
def raise_nested_exceptions
48+
raise_nested_exceptions_third
49+
end
50+
51+
def raise_nested_exceptions_first
4852
raise "First error"
53+
end
54+
55+
def raise_nested_exceptions_second
56+
raise_nested_exceptions_first
4957
rescue
50-
begin
51-
raise "Second error"
52-
rescue
53-
raise "Third error"
54-
end
58+
raise "Second error"
5559
end
5660

61+
def raise_nested_exceptions_third
62+
raise_nested_exceptions_second
63+
rescue
64+
raise "Third error"
65+
end
66+
67+
5768
def call(env)
5869
env["action_dispatch.show_detailed_exceptions"] = @detailed
5970
req = ActionDispatch::Request.new(env)
@@ -641,29 +652,67 @@ def self.build_app(app, *args)
641652
Information for: RuntimeError (Third error):
642653
MSG
643654

644-
assert_match Regexp.new(<<~REGEX.strip), paragraphs[2].lines[0..2].join
645-
\\A.*in `rescue in rescue in raise_nested_exceptions'
646-
.*in `rescue in raise_nested_exceptions'
647-
.*in `raise_nested_exceptions'
648-
REGEX
649-
650-
assert_includes(paragraphs[3], <<~MSG.strip)
651-
Information for cause: RuntimeError (Second error):
652-
MSG
653-
654-
assert_match Regexp.new(<<~REGEX.strip), paragraphs[4].lines[0..1].join
655-
\\A.*in `rescue in raise_nested_exceptions'
656-
.*in `raise_nested_exceptions'
657-
REGEX
658-
659-
660-
assert_includes(paragraphs[5], <<~MSG.strip)
661-
Information for cause: RuntimeError (First error):
662-
MSG
663-
664-
assert_match Regexp.new(<<~REGEX.strip), paragraphs[6].lines[0]
665-
\\A.*in `raise_nested_exceptions'
666-
REGEX
655+
if RUBY_VERSION >= "3.4"
656+
# Changes to the format of exception backtraces
657+
# https://bugs.ruby-lang.org/issues/16495 (use single quote instead of backtrace)
658+
# https://bugs.ruby-lang.org/issues/20275 (don't have entry for rescue in)
659+
# And probably more, they now show the class too
660+
assert_match Regexp.new(<<~REGEX.strip), paragraphs[2]
661+
\\A.*in '.*raise_nested_exceptions_third'
662+
.*in '.*raise_nested_exceptions'
663+
REGEX
664+
665+
assert_includes(paragraphs[3], <<~MSG.strip)
666+
Information for cause: RuntimeError (Second error):
667+
MSG
668+
669+
assert_match Regexp.new(<<~REGEX.strip), paragraphs[4]
670+
\\A.*in '.*raise_nested_exceptions_second'
671+
.*in '.*raise_nested_exceptions_third'
672+
.*in '.*raise_nested_exceptions'
673+
REGEX
674+
675+
676+
assert_includes(paragraphs[5], <<~MSG.strip)
677+
Information for cause: RuntimeError (First error):
678+
MSG
679+
680+
assert_match Regexp.new(<<~REGEX.strip), paragraphs[6]
681+
\\A.*in '.*raise_nested_exceptions_first'
682+
.*in '.*raise_nested_exceptions_second'
683+
.*in '.*raise_nested_exceptions_third'
684+
.*in '.*raise_nested_exceptions'
685+
REGEX
686+
else
687+
assert_match Regexp.new(<<~REGEX.strip), paragraphs[2]
688+
\\A.*in `rescue in raise_nested_exceptions_third'
689+
.*in `raise_nested_exceptions_third'
690+
.*in `raise_nested_exceptions'
691+
REGEX
692+
693+
assert_includes(paragraphs[3], <<~MSG.strip)
694+
Information for cause: RuntimeError (Second error):
695+
MSG
696+
697+
assert_match Regexp.new(<<~REGEX.strip), paragraphs[4]
698+
\\A.*in `rescue in raise_nested_exceptions_second'
699+
.*in `raise_nested_exceptions_second'
700+
.*in `raise_nested_exceptions_third'
701+
.*in `raise_nested_exceptions'
702+
REGEX
703+
704+
705+
assert_includes(paragraphs[5], <<~MSG.strip)
706+
Information for cause: RuntimeError (First error):
707+
MSG
708+
709+
assert_match Regexp.new(<<~REGEX.strip), paragraphs[6]
710+
\\A.*in `raise_nested_exceptions_first'
711+
.*in `raise_nested_exceptions_second'
712+
.*in `raise_nested_exceptions_third'
713+
.*in `raise_nested_exceptions'
714+
REGEX
715+
end
667716
end
668717

669718
test "display backtrace when error type is SyntaxError" do
@@ -783,28 +832,28 @@ def self.build_app(app, *args)
783832
# Possible Ruby 3.4-dev bug: https://bugs.ruby-lang.org/issues/19117#note-45
784833
# assert application trace refers to line that raises the last exception
785834
assert_select "#Application-Trace-0" do
786-
assert_select "code a:first", %r{in '.*raise_nested_exceptions'}
835+
assert_select "code a:first", %r{in '.*raise_nested_exceptions_third'}
787836
end
788837

789838
# assert the second application trace refers to the line that raises the second exception
790839
assert_select "#Application-Trace-1" do
791-
assert_select "code a:first", %r{in '.*raise_nested_exceptions'}
840+
assert_select "code a:first", %r{in '.*raise_nested_exceptions_second'}
792841
end
793842
else
794843
# assert application trace refers to line that raises the last exception
795844
assert_select "#Application-Trace-0" do
796-
assert_select "code a:first", %r{in [`']rescue in rescue in .*raise_nested_exceptions'}
845+
assert_select "code a:first", %r{in [`']rescue in .*raise_nested_exceptions_third'}
797846
end
798847

799848
# assert the second application trace refers to the line that raises the second exception
800849
assert_select "#Application-Trace-1" do
801-
assert_select "code a:first", %r{in [`']rescue in .*raise_nested_exceptions'}
850+
assert_select "code a:first", %r{in [`']rescue in .*raise_nested_exceptions_second'}
802851
end
803852
end
804853

805854
# assert the third application trace refers to the line that raises the first exception
806855
assert_select "#Application-Trace-2" do
807-
assert_select "code a:first", %r{in [`'].*raise_nested_exceptions'}
856+
assert_select "code a:first", %r{in [`'].*raise_nested_exceptions_first'}
808857
end
809858
end
810859
end

0 commit comments

Comments
 (0)