Skip to content

Commit f58f68d

Browse files
committed
Remove Kernel#caller hack and avoid exception throwing for metadata
Should close out #36
1 parent 46be2e1 commit f58f68d

File tree

6 files changed

+12
-60
lines changed

6 files changed

+12
-60
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Opal 0.10 support
55
* Arity checking enabled by default
66
* Dropped support for PhantomJS < 2.0
7+
* Removed `Kernel#caller` monkey patch so test file/line metadata is only available if supplied via test metadata or for failures. Should improve performance since an exception isn't thrown for every test to gather the data
78

89
## 0.5.0 (2015-12-08)
910

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ RSpec.configure do |c|
266266
c.include TestMod
267267
end
268268
```
269-
* Formatting
270-
* Backtrace info on specs is buggy ([no Kernel::caller method in Opal](https://github.com/opal/opal/issues/894)), in Firefox w/ the browser runner, no backtraces show up with failed specs
269+
* Formatting/Reporting
270+
* Specs will not have file path/line number information on them unless they are supplied from user metadata or they fail, see [this issue](https://github.com/opal/opal-rspec/issues/36)
271+
* In Firefox w/ the browser runner, no backtraces show up with failed specs
271272
* Diffs are not yet available when objects do not meet expectations (diff-lcs gem dependency has not been dealt with yet in Opal)
272273
* Configuration
273274
* Not all RSpec runner options are supported yet

opal/opal/rspec/fixes/opal.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
require_relative 'opal/compatibility'
2-
require_relative 'opal/kernel'

opal/opal/rspec/fixes/opal/kernel.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

opal/opal/rspec/fixes/rspec/core/metadata.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ module ::RSpec::Core::Metadata
22
class HashPopulator
33
def populate_location_attributes
44
backtrace = user_metadata.delete(:caller)
5+
# Throwing exceptions to get code location is expensive, so use this if the user supplied it, otherwise
6+
# keep empty stuff around so filter code does not crash
57

6-
file_path, line_number = if backtrace
8+
# might have an empty array from caller which file_path_and_line_number_from doesn't like
9+
file_path, line_number = if backtrace && !backtrace.empty?
710
file_path_and_line_number_from(backtrace)
8-
# Opal 0.9 has a stub for this but it does not return anything
9-
# elsif block.respond_to?(:source_location)
10-
# block.source_location
1111
else
12-
file_path_and_line_number_from(caller)
12+
['', -1]
1313
end
1414

15-
file_path = Metadata.relative_path(file_path)
16-
metadata[:file_path] = file_path
15+
metadata[:file_path] = file_path
1716
metadata[:line_number] = line_number.to_i
18-
metadata[:location] = "#{file_path}:#{line_number}"
17+
metadata[:location] = file_path.empty? ? '' : "#{file_path}:#{line_number}"
1918
end
2019
end
2120
end

spec/mri/integration/spec_opts_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
'description' => 'should eq 42',
3939
'full_description' => 'foobar should eq 42',
4040
'status' => 'passed',
41-
'file_path' => /\S+/,
41+
'file_path' => '',
4242
'line_number' => be_a(Fixnum),
4343
'run_time' => be_a(Float)}
4444
],

0 commit comments

Comments
 (0)