|
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[0] |
| 20 | + file = @proc.source_location.first |
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[0] |
| 24 | + file = @proc_new.source_location.first |
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[0] |
| 28 | + file = @lambda.source_location.first |
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[0] |
| 32 | + file = @method.source_location.first |
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 second value to an Integer representing the line on which the proc was defined" do |
38 | | - line = @proc.source_location[1] |
| 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 |
39 | 39 | line.should be_an_instance_of(Integer) |
40 | 40 | line.should == 4 |
41 | 41 |
|
42 | | - line = @proc_new.source_location[1] |
| 42 | + line = @proc_new.source_location.last |
43 | 43 | line.should be_an_instance_of(Integer) |
44 | 44 | line.should == 12 |
45 | 45 |
|
46 | | - line = @lambda.source_location[1] |
| 46 | + line = @lambda.source_location.last |
47 | 47 | line.should be_an_instance_of(Integer) |
48 | 48 | line.should == 8 |
49 | 49 |
|
50 | | - line = @method.source_location[1] |
| 50 | + line = @method.source_location.last |
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 | | - 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 |
| 56 | + proc { true }.source_location.should == [__FILE__, __LINE__] |
| 57 | + Proc.new { true }.source_location.should == [__FILE__, __LINE__] |
| 58 | + -> { true }.source_location.should == [__FILE__, __LINE__] |
66 | 59 | end |
67 | 60 |
|
68 | 61 | it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do |
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 |
| 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 |
72 | 65 | end |
73 | 66 |
|
74 | 67 | it "returns the location of the proc's body; not necessarily the proc itself" do |
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 |
| 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 |
78 | 71 | end |
79 | 72 |
|
80 | 73 | it "returns the same value for a proc-ified method as the method reports" do |
|
93 | 86 |
|
94 | 87 | it "works for eval with a given line" do |
95 | 88 | proc = eval('-> {}', nil, "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 |
| 89 | + proc.source_location.should == ["foo", 100] |
103 | 90 | end |
104 | 91 | end |
0 commit comments