|
1 | 1 | require_relative '../../spec_helper' |
2 | 2 | require_relative 'fixtures/common' |
| 3 | +require_relative 'shared/set_backtrace' |
3 | 4 |
|
4 | 5 | describe "Exception#set_backtrace" do |
5 | | - it "accepts an Array of Strings" do |
6 | | - err = RuntimeError.new |
7 | | - err.set_backtrace ["unhappy"] |
8 | | - err.backtrace.should == ["unhappy"] |
9 | | - end |
10 | | - |
11 | 6 | it "allows the user to set the backtrace from a rescued exception" do |
12 | 7 | bt = ExceptionSpecs::Backtrace.backtrace |
13 | 8 | err = RuntimeError.new |
|
20 | 15 | err.backtrace_locations.should == nil |
21 | 16 | end |
22 | 17 |
|
23 | | - ruby_version_is "3.4" do |
24 | | - it "allows the user to set backtrace locations from a rescued exception" do |
25 | | - bt_locations = ExceptionSpecs::Backtrace.backtrace_locations |
26 | | - err = RuntimeError.new |
27 | | - err.backtrace.should == nil |
28 | | - err.backtrace_locations.should == nil |
29 | | - |
30 | | - err.set_backtrace bt_locations |
31 | | - |
32 | | - err.backtrace_locations.size.should == bt_locations.size |
33 | | - err.backtrace_locations.each_with_index do |loc, index| |
34 | | - other_loc = bt_locations[index] |
35 | | - |
36 | | - loc.path.should == other_loc.path |
37 | | - loc.label.should == other_loc.label |
38 | | - loc.base_label.should == other_loc.base_label |
39 | | - loc.lineno.should == other_loc.lineno |
40 | | - loc.absolute_path.should == other_loc.absolute_path |
41 | | - loc.to_s.should == other_loc.to_s |
42 | | - end |
43 | | - err.backtrace.size.should == err.backtrace_locations.size |
44 | | - end |
45 | | - end |
46 | | - |
47 | | - it "accepts an empty Array" do |
48 | | - err = RuntimeError.new |
49 | | - err.set_backtrace [] |
50 | | - err.backtrace.should == [] |
51 | | - end |
52 | | - |
53 | | - it "accepts a String" do |
| 18 | + it_behaves_like :exception_set_backtrace, ->(*backtrace) { |
54 | 19 | err = RuntimeError.new |
55 | | - err.set_backtrace "unhappy" |
56 | | - err.backtrace.should == ["unhappy"] |
57 | | - end |
58 | | - |
59 | | - it "accepts nil" do |
60 | | - err = RuntimeError.new |
61 | | - err.set_backtrace nil |
62 | | - err.backtrace.should be_nil |
63 | | - end |
64 | | - |
65 | | - it "raises a TypeError when passed a Symbol" do |
66 | | - err = RuntimeError.new |
67 | | - -> { err.set_backtrace :unhappy }.should raise_error(TypeError) |
68 | | - end |
69 | | - |
70 | | - it "raises a TypeError when the Array contains a Symbol" do |
71 | | - err = RuntimeError.new |
72 | | - -> { err.set_backtrace ["String", :unhappy] }.should raise_error(TypeError) |
73 | | - end |
74 | | - |
75 | | - it "raises a TypeError when the array contains nil" do |
76 | | - err = Exception.new |
77 | | - -> { err.set_backtrace ["String", nil] }.should raise_error(TypeError) |
78 | | - end |
79 | | - |
80 | | - it "raises a TypeError when the argument is a nested array" do |
81 | | - err = Exception.new |
82 | | - -> { err.set_backtrace ["String", ["String"]] }.should raise_error(TypeError) |
83 | | - end |
| 20 | + err.set_backtrace(backtrace.first) unless backtrace.empty? |
| 21 | + err |
| 22 | + } |
84 | 23 | end |
0 commit comments