|
17 | 17 | end |
18 | 18 |
|
19 | 19 | it "sets the first value to the path of the file in which the proc was defined" do |
20 | | - file = @proc.source_location.first |
| 20 | + file = @proc.source_location[0] |
21 | 21 | file.should be_an_instance_of(String) |
22 | 22 | file.should == File.realpath('fixtures/source_location.rb', __dir__) |
23 | 23 |
|
24 | | - file = @proc_new.source_location.first |
| 24 | + file = @proc_new.source_location[0] |
25 | 25 | file.should be_an_instance_of(String) |
26 | 26 | file.should == File.realpath('fixtures/source_location.rb', __dir__) |
27 | 27 |
|
28 | | - file = @lambda.source_location.first |
| 28 | + file = @lambda.source_location[0] |
29 | 29 | file.should be_an_instance_of(String) |
30 | 30 | file.should == File.realpath('fixtures/source_location.rb', __dir__) |
31 | 31 |
|
32 | | - file = @method.source_location.first |
| 32 | + file = @method.source_location[0] |
33 | 33 | file.should be_an_instance_of(String) |
34 | 34 | file.should == File.realpath('fixtures/source_location.rb', __dir__) |
35 | 35 | end |
36 | 36 |
|
37 | | - it "sets the last value to an Integer representing the line on which the proc was defined" do |
38 | | - line = @proc.source_location.last |
| 37 | + it "sets the second value to an Integer representing the line on which the proc was defined" do |
| 38 | + line = @proc.source_location[1] |
39 | 39 | line.should be_an_instance_of(Integer) |
40 | 40 | line.should == 4 |
41 | 41 |
|
42 | | - line = @proc_new.source_location.last |
| 42 | + line = @proc_new.source_location[1] |
43 | 43 | line.should be_an_instance_of(Integer) |
44 | 44 | line.should == 12 |
45 | 45 |
|
46 | | - line = @lambda.source_location.last |
| 46 | + line = @lambda.source_location[1] |
47 | 47 | line.should be_an_instance_of(Integer) |
48 | 48 | line.should == 8 |
49 | 49 |
|
50 | | - line = @method.source_location.last |
| 50 | + line = @method.source_location[1] |
51 | 51 | line.should be_an_instance_of(Integer) |
52 | 52 | line.should == 15 |
53 | 53 | end |
54 | 54 |
|
55 | 55 | it "works even if the proc was created on the same line" do |
56 | | - proc { true }.source_location.should == [__FILE__, __LINE__] |
57 | | - Proc.new { true }.source_location.should == [__FILE__, __LINE__] |
58 | | - -> { true }.source_location.should == [__FILE__, __LINE__] |
| 56 | + ruby_version_is(""..."4.0") do |
| 57 | + proc { true }.source_location.should == [__FILE__, __LINE__] |
| 58 | + Proc.new { true }.source_location.should == [__FILE__, __LINE__] |
| 59 | + -> { true }.source_location.should == [__FILE__, __LINE__] |
| 60 | + end |
| 61 | + ruby_version_is("4.0") do |
| 62 | + proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19] |
| 63 | + Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23] |
| 64 | + -> { true }.source_location.should == [__FILE__, __LINE__, 8, __LINE__, 17] |
| 65 | + end |
59 | 66 | end |
60 | 67 |
|
61 | 68 | it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do |
62 | | - ProcSpecs::SourceLocation.my_multiline_proc.source_location.last.should == 20 |
63 | | - ProcSpecs::SourceLocation.my_multiline_proc_new.source_location.last.should == 34 |
64 | | - ProcSpecs::SourceLocation.my_multiline_lambda.source_location.last.should == 27 |
| 69 | + ProcSpecs::SourceLocation.my_multiline_proc.source_location[1].should == 20 |
| 70 | + ProcSpecs::SourceLocation.my_multiline_proc_new.source_location[1].should == 34 |
| 71 | + ProcSpecs::SourceLocation.my_multiline_lambda.source_location[1].should == 27 |
65 | 72 | end |
66 | 73 |
|
67 | 74 | it "returns the location of the proc's body; not necessarily the proc itself" do |
68 | | - ProcSpecs::SourceLocation.my_detached_proc.source_location.last.should == 41 |
69 | | - ProcSpecs::SourceLocation.my_detached_proc_new.source_location.last.should == 51 |
70 | | - ProcSpecs::SourceLocation.my_detached_lambda.source_location.last.should == 46 |
| 75 | + ProcSpecs::SourceLocation.my_detached_proc.source_location[1].should == 41 |
| 76 | + ProcSpecs::SourceLocation.my_detached_proc_new.source_location[1].should == 51 |
| 77 | + ProcSpecs::SourceLocation.my_detached_lambda.source_location[1].should == 46 |
71 | 78 | end |
72 | 79 |
|
73 | 80 | it "returns the same value for a proc-ified method as the method reports" do |
|
86 | 93 |
|
87 | 94 | it "works for eval with a given line" do |
88 | 95 | proc = eval('-> {}', nil, "foo", 100) |
89 | | - proc.source_location.should == ["foo", 100] |
| 96 | + location = proc.source_location |
| 97 | + ruby_version_is(""..."4.0") do |
| 98 | + location.should == ["foo", 100] |
| 99 | + end |
| 100 | + ruby_version_is("4.0") do |
| 101 | + location.should == ["foo", 100, 2, 100, 5] |
| 102 | + end |
90 | 103 | end |
91 | 104 | end |
0 commit comments