Skip to content

Commit 35537b8

Browse files
mameeregon
authored andcommitted
ruby-spec: Accept the receiver in backtraces
1 parent 4ceb700 commit 35537b8

File tree

12 files changed

+53
-39
lines changed

12 files changed

+53
-39
lines changed

command_line/backtrace_limit_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454

5555
out.should == <<-MSG
5656
top
57-
/fixtures/backtrace.rb:2:in 'a': oops (RuntimeError)
58-
\tfrom /fixtures/backtrace.rb:6:in 'b'
59-
\tfrom /fixtures/backtrace.rb:10:in 'c'
57+
/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
58+
\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
59+
\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
6060
\t ... 2 levels...
6161
MSG
6262
end
@@ -68,9 +68,9 @@
6868

6969
out.should == <<-MSG
7070
full_message
71-
/fixtures/backtrace.rb:2:in 'a': oops (RuntimeError)
72-
\tfrom /fixtures/backtrace.rb:6:in 'b'
73-
\tfrom /fixtures/backtrace.rb:10:in 'c'
71+
/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
72+
\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
73+
\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
7474
\t ... 2 levels...
7575
MSG
7676
end
@@ -82,10 +82,10 @@
8282

8383
out.should == <<-MSG
8484
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'
8989
/fixtures/backtrace.rb:29:in '<main>'
9090
MSG
9191
end

core/exception/backtrace_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
end
2828

2929
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'/
3131
end
3232

3333
it "includes the filename of the location immediately prior to where self raised in the second element" do

core/exception/top_level_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def raise_wrapped
2020
end
2121
RUBY
2222
lines = ruby_exe(code, args: "2>&1", exit_status: 1).lines
23-
lines.reject! { |l| l.include?('rescue in') }
2423
lines.map! { |l| l.chomp[/:(in.+)/, 1] }
25-
lines.size.should == 4
26-
lines[0].should =~ /\Ain [`']raise_wrapped': wrapped \(RuntimeError\)\z/
27-
lines[1].should =~ /\Ain [`']<main>'\z/
28-
lines[2].should =~ /\Ain [`']raise_cause': the cause \(RuntimeError\)\z/
29-
lines[3].should =~ /\Ain [`']<main>'\z/
24+
lines.size.should == 5
25+
lines[0].should =~ /\Ain [`'](?:Object#)?raise_wrapped': wrapped \(RuntimeError\)\z/
26+
lines[1].should =~ /\Ain [`'](?:rescue in )?<main>'\z/
27+
lines[2].should =~ /\Ain [`']<main>'\z/
28+
lines[3].should =~ /\Ain [`'](?:Object#)?raise_cause': the cause \(RuntimeError\)\z/
29+
lines[4].should =~ /\Ain [`']<main>'\z/
3030
end
3131

3232
describe "with a custom backtrace" do

core/kernel/caller_locations_spec.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,28 @@
7171
end
7272

7373
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
8296
end
8397
end
8498
end

core/kernel/caller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
path = fixture(__FILE__, "caller_at_exit.rb")
4040
lines = ruby_exe(path).lines
4141
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/
4343
lines[1].should =~ /\A#{path}:2:in [`']block in <main>'\n\z/
4444
end
4545

@@ -62,7 +62,7 @@
6262

6363
loc = nil
6464
tap { loc = caller(1, 1)[0] }
65-
loc.should =~ /\A<internal:.*in [`']tap'\z/
65+
loc.should =~ /\A<internal:.*in [`'](?:Kernel#)?tap'\z/
6666
end
6767
end
6868
end

core/kernel/public_send_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ def bar
105105
end
106106

107107
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'/ }
109109
end
110110

111111
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'/ }
113113
end
114114

115115
it_behaves_like :basicobject_send, :public_send

core/thread/backtrace/location/absolute_path_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
it "returns nil" do
6060
location = nil
6161
tap { location = caller_locations(1, 1)[0] }
62-
location.label.should == "tap"
62+
location.label.should =~ /\A(?:Kernel#)?tap\z/
6363
if location.path.start_with?("<internal:")
6464
location.absolute_path.should == nil
6565
else

core/thread/backtrace/location/label_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
end
88

99
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/
1111
end
1212

1313
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 =~ /\Ablock in (?:ThreadBacktraceLocationSpecs\.)?block_location\z/
1515
end
1616

1717
it 'returns the module name for a module location' do
@@ -22,9 +22,9 @@
2222
first_level_location, second_level_location, third_level_location =
2323
ThreadBacktraceLocationSpecs.locations_inside_nested_blocks
2424

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 =~ /\Ablock in (?:ThreadBacktraceLocationSpecs\.)?locations_inside_nested_blocks\z/
26+
second_level_location.label.should =~ /\Ablock \(2 levels\) in (?:ThreadBacktraceLocationSpecs\.)?locations_inside_nested_blocks\z/
27+
third_level_location.label.should =~ /\Ablock \(3 levels\) in (?:ThreadBacktraceLocationSpecs\.)?locations_inside_nested_blocks\z/
2828
end
2929

3030
it 'sets the location label for a top-level block differently depending on it being in the main file or a required file' do

core/thread/backtrace_locations_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
end
7171

7272
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/
7474
end
7575

7676
it "[1..-1] is the same as #caller_locations(0..-1) for Thread.current" do

core/thread/backtrace_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
backtrace = t.backtrace
1515
backtrace.should be_kind_of(Array)
16-
backtrace.first.should =~ /[`']sleep'/
16+
backtrace.first.should =~ /[`'](?:Kernel#)?sleep'/
1717

1818
t.raise 'finish the thread'
1919
t.join

0 commit comments

Comments
 (0)