File tree Expand file tree Collapse file tree 12 files changed +53
-39
lines changed Expand file tree Collapse file tree 12 files changed +53
-39
lines changed Original file line number Diff line number Diff line change 54
54
55
55
out . should == <<-MSG
56
56
top
57
- /fixtures/backtrace.rb:2:in 'a': oops (RuntimeError)
58
- \t from /fixtures/backtrace.rb:6:in 'b'
59
- \t from /fixtures/backtrace.rb:10:in 'c'
57
+ /fixtures/backtrace.rb:2:in 'Object# a': oops (RuntimeError)
58
+ \t from /fixtures/backtrace.rb:6:in 'Object# b'
59
+ \t from /fixtures/backtrace.rb:10:in 'Object# c'
60
60
\t ... 2 levels...
61
61
MSG
62
62
end
68
68
69
69
out . should == <<-MSG
70
70
full_message
71
- /fixtures/backtrace.rb:2:in 'a': oops (RuntimeError)
72
- \t from /fixtures/backtrace.rb:6:in 'b'
73
- \t from /fixtures/backtrace.rb:10:in 'c'
71
+ /fixtures/backtrace.rb:2:in 'Object# a': oops (RuntimeError)
72
+ \t from /fixtures/backtrace.rb:6:in 'Object# b'
73
+ \t from /fixtures/backtrace.rb:10:in 'Object# c'
74
74
\t ... 2 levels...
75
75
MSG
76
76
end
82
82
83
83
out . should == <<-MSG
84
84
backtrace
85
- /fixtures/backtrace.rb:2:in 'a'
86
- /fixtures/backtrace.rb:6:in 'b'
87
- /fixtures/backtrace.rb:10:in 'c'
88
- /fixtures/backtrace.rb:14:in 'd'
85
+ /fixtures/backtrace.rb:2:in 'Object# a'
86
+ /fixtures/backtrace.rb:6:in 'Object# b'
87
+ /fixtures/backtrace.rb:10:in 'Object# c'
88
+ /fixtures/backtrace.rb:14:in 'Object# d'
89
89
/fixtures/backtrace.rb:29:in '<main>'
90
90
MSG
91
91
end
Original file line number Diff line number Diff line change 27
27
end
28
28
29
29
it "includes the name of the method from where self raised in the first element" do
30
- @backtrace . first . should =~ /in [`']backtrace'/
30
+ @backtrace . first . should =~ /in [`'](?:ExceptionSpecs::Backtrace \. )? backtrace'/
31
31
end
32
32
33
33
it "includes the filename of the location immediately prior to where self raised in the second element" do
Original file line number Diff line number Diff line change @@ -20,13 +20,13 @@ def raise_wrapped
20
20
end
21
21
RUBY
22
22
lines = ruby_exe ( code , args : "2>&1" , exit_status : 1 ) . lines
23
- lines . reject! { |l | l . include? ( 'rescue in' ) }
24
23
lines . map! { |l | l . chomp [ /:(in.+)/ , 1 ] }
25
- lines . size . should == 4
26
- lines [ 0 ] . should =~ /\A in [`']raise_wrapped': wrapped \( RuntimeError\) \z /
27
- lines [ 1 ] . should =~ /\A in [`']<main>'\z /
28
- lines [ 2 ] . should =~ /\A in [`']raise_cause': the cause \( RuntimeError\) \z /
29
- lines [ 3 ] . should =~ /\A in [`']<main>'\z /
24
+ lines . size . should == 5
25
+ lines [ 0 ] . should =~ /\A in [`'](?:Object#)?raise_wrapped': wrapped \( RuntimeError\) \z /
26
+ lines [ 1 ] . should =~ /\A in [`'](?:rescue in )?<main>'\z /
27
+ lines [ 2 ] . should =~ /\A in [`']<main>'\z /
28
+ lines [ 3 ] . should =~ /\A in [`'](?:Object#)?raise_cause': the cause \( RuntimeError\) \z /
29
+ lines [ 4 ] . should =~ /\A in [`']<main>'\z /
30
30
end
31
31
32
32
describe "with a custom backtrace" do
Original file line number Diff line number Diff line change 71
71
end
72
72
73
73
guard -> { Kernel . instance_method ( :tap ) . source_location } do
74
- it "includes core library methods defined in Ruby" do
75
- file , line = Kernel . instance_method ( :tap ) . source_location
76
- file . should . start_with? ( '<internal:' )
77
-
78
- loc = nil
79
- tap { loc = caller_locations ( 1 , 1 ) [ 0 ] }
80
- loc . label . should == "tap"
81
- loc . path . should . start_with? "<internal:"
74
+ ruby_version_is "" ..."3.4" do
75
+ it "includes core library methods defined in Ruby" do
76
+ file , line = Kernel . instance_method ( :tap ) . source_location
77
+ file . should . start_with? ( '<internal:' )
78
+
79
+ loc = nil
80
+ tap { loc = caller_locations ( 1 , 1 ) [ 0 ] }
81
+ loc . label . should == "tap"
82
+ loc . path . should . start_with? "<internal:"
83
+ end
84
+ end
85
+
86
+ ruby_version_is "3.4" do
87
+ it "includes core library methods defined in Ruby" do
88
+ file , line = Kernel . instance_method ( :tap ) . source_location
89
+ file . should . start_with? ( '<internal:' )
90
+
91
+ loc = nil
92
+ tap { loc = caller_locations ( 1 , 1 ) [ 0 ] }
93
+ loc . label . should == "Kernel#tap"
94
+ loc . path . should . start_with? "<internal:"
95
+ end
82
96
end
83
97
end
84
98
end
Original file line number Diff line number Diff line change 39
39
path = fixture ( __FILE__ , "caller_at_exit.rb" )
40
40
lines = ruby_exe ( path ) . lines
41
41
lines . size . should == 2
42
- lines [ 0 ] . should =~ /\A #{ path } :6:in [`']foo'\n \z /
42
+ lines [ 0 ] . should =~ /\A #{ path } :6:in [`'](?:Object#)? foo'\n \z /
43
43
lines [ 1 ] . should =~ /\A #{ path } :2:in [`']block in <main>'\n \z /
44
44
end
45
45
62
62
63
63
loc = nil
64
64
tap { loc = caller ( 1 , 1 ) [ 0 ] }
65
- loc . should =~ /\A <internal:.*in [`']tap'\z /
65
+ loc . should =~ /\A <internal:.*in [`'](?:Kernel#)? tap'\z /
66
66
end
67
67
end
68
68
end
Original file line number Diff line number Diff line change @@ -105,11 +105,11 @@ def bar
105
105
end
106
106
107
107
it "includes `public_send` in the backtrace when passed not enough arguments" do
108
- -> { public_send ( ) } . should raise_error ( ArgumentError ) { |e | e . backtrace [ 0 ] . should =~ /[`']public_send'/ }
108
+ -> { public_send ( ) } . should raise_error ( ArgumentError ) { |e | e . backtrace [ 0 ] . should =~ /[`'](?:Kernel#)? public_send'/ }
109
109
end
110
110
111
111
it "includes `public_send` in the backtrace when passed a single incorrect argument" do
112
- -> { public_send ( Object . new ) } . should raise_error ( TypeError ) { |e | e . backtrace [ 0 ] . should =~ /[`']public_send'/ }
112
+ -> { public_send ( Object . new ) } . should raise_error ( TypeError ) { |e | e . backtrace [ 0 ] . should =~ /[`'](?:Kernel#)? public_send'/ }
113
113
end
114
114
115
115
it_behaves_like :basicobject_send , :public_send
Original file line number Diff line number Diff line change 59
59
it "returns nil" do
60
60
location = nil
61
61
tap { location = caller_locations ( 1 , 1 ) [ 0 ] }
62
- location . label . should == " tap"
62
+ location . label . should =~ / \A (?:Kernel#)? tap\z /
63
63
if location . path . start_with? ( "<internal:" )
64
64
location . absolute_path . should == nil
65
65
else
Original file line number Diff line number Diff line change 7
7
end
8
8
9
9
it 'returns the method name for a method location' do
10
- ThreadBacktraceLocationSpecs . method_location [ 0 ] . label . should == " method_location"
10
+ ThreadBacktraceLocationSpecs . method_location [ 0 ] . label . should =~ / \A (?:ThreadBacktraceLocationSpecs \. )? method_location\z /
11
11
end
12
12
13
13
it 'returns the block name for a block location' do
14
- ThreadBacktraceLocationSpecs . block_location [ 0 ] . label . should == "block in block_location"
14
+ ThreadBacktraceLocationSpecs . block_location [ 0 ] . label . should =~ / \A block in (?:ThreadBacktraceLocationSpecs \. )? block_location\z /
15
15
end
16
16
17
17
it 'returns the module name for a module location' do
22
22
first_level_location , second_level_location , third_level_location =
23
23
ThreadBacktraceLocationSpecs . locations_inside_nested_blocks
24
24
25
- first_level_location . label . should == 'block in locations_inside_nested_blocks'
26
- second_level_location . label . should == 'block (2 levels) in locations_inside_nested_blocks'
27
- third_level_location . label . should == 'block (3 levels) in locations_inside_nested_blocks'
25
+ first_level_location . label . should =~ / \A block in (?:ThreadBacktraceLocationSpecs \. )? locations_inside_nested_blocks\z /
26
+ second_level_location . label . should =~ / \A block \ ( 2 levels\ ) in (?:ThreadBacktraceLocationSpecs \. )? locations_inside_nested_blocks\z /
27
+ third_level_location . label . should =~ / \A block \ ( 3 levels\ ) in (?:ThreadBacktraceLocationSpecs \. )? locations_inside_nested_blocks\z /
28
28
end
29
29
30
30
it 'sets the location label for a top-level block differently depending on it being in the main file or a required file' do
Original file line number Diff line number Diff line change 70
70
end
71
71
72
72
it "the first location reports the call to #backtrace_locations" do
73
- Thread . current . backtrace_locations ( 0 ..0 ) [ 0 ] . to_s . should =~ /\A #{ __FILE__ } :#{ __LINE__ } :in [`']backtrace_locations'\z /
73
+ Thread . current . backtrace_locations ( 0 ..0 ) [ 0 ] . to_s . should =~ /\A #{ __FILE__ } :#{ __LINE__ } :in [`'](?:Thread#)? backtrace_locations'\z /
74
74
end
75
75
76
76
it "[1..-1] is the same as #caller_locations(0..-1) for Thread.current" do
Original file line number Diff line number Diff line change 13
13
14
14
backtrace = t . backtrace
15
15
backtrace . should be_kind_of ( Array )
16
- backtrace . first . should =~ /[`']sleep'/
16
+ backtrace . first . should =~ /[`'](?:Kernel#)? sleep'/
17
17
18
18
t . raise 'finish the thread'
19
19
t . join
You can’t perform that action at this time.
0 commit comments