Skip to content

Commit

Permalink
Remove Kernel#caller hack and avoid exception throwing for metadata
Browse files Browse the repository at this point in the history
Should close out #36
  • Loading branch information
wied03 committed Apr 20, 2016
1 parent 53df4a1 commit 6e2806b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Opal 0.10 support
* Arity checking enabled by default
* Dropped support for PhantomJS < 2.0
* 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

## 0.5.0 (2015-12-08)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ RSpec.configure do |c|
c.include TestMod
end
```
* Formatting
* 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
* Formatting/Reporting
* 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)
* In Firefox w/ the browser runner, no backtraces show up with failed specs
* Diffs are not yet available when objects do not meet expectations (diff-lcs gem dependency has not been dealt with yet in Opal)
* Configuration
* Not all RSpec runner options are supported yet
Expand Down
1 change: 0 additions & 1 deletion opal/opal/rspec/fixes/opal.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
require_relative 'opal/compatibility'
require_relative 'opal/kernel'
48 changes: 0 additions & 48 deletions opal/opal/rspec/fixes/opal/kernel.rb

This file was deleted.

15 changes: 7 additions & 8 deletions opal/opal/rspec/fixes/rspec/core/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ module ::RSpec::Core::Metadata
class HashPopulator
def populate_location_attributes
backtrace = user_metadata.delete(:caller)
# Throwing exceptions to get code location is expensive, so use this if the user supplied it, otherwise
# keep empty stuff around so filter code does not crash

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

file_path = Metadata.relative_path(file_path)
metadata[:file_path] = file_path
metadata[:file_path] = file_path
metadata[:line_number] = line_number.to_i
metadata[:location] = "#{file_path}:#{line_number}"
metadata[:location] = file_path.empty? ? '' : "#{file_path}:#{line_number}"
end
end
end

0 comments on commit 6e2806b

Please sign in to comment.