Class: RSpock::BacktraceFilter
- Inherits:
-
Object
- Object
- RSpock::BacktraceFilter
- Defined in:
- lib/rspock/backtrace_filter.rb
Instance Method Summary collapse
-
#filter_exception(exception) ⇒ void
Filters the backtrace of the given
exception
and applies the filtered backtrace to the exception. -
#filter_string(location) ⇒ String
Filters the given location.
-
#initialize(source_map_provider: ::ASTTransform::SourceMap) ⇒ BacktraceFilter
constructor
Constructs a new BacktraceFilter instance.
Constructor Details
#initialize(source_map_provider: ::ASTTransform::SourceMap) ⇒ BacktraceFilter
Constructs a new BacktraceFilter instance.
9 10 11 |
# File 'lib/rspock/backtrace_filter.rb', line 9 def initialize(source_map_provider: ::ASTTransform::SourceMap) @source_map_provider = source_map_provider end |
Instance Method Details
#filter_exception(exception) ⇒ void
This method returns an undefined value.
Filters the backtrace of the given exception
and applies the filtered backtrace to the exception.
18 19 20 |
# File 'lib/rspock/backtrace_filter.rb', line 18 def filter_exception(exception) exception.set_backtrace(source_mapped_backtrace(exception)) end |
#filter_string(location) ⇒ String
Filters the given location.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rspock/backtrace_filter.rb', line 27 def filter_string(location) file_path, lineno = location.match(/([\S]+):(\d+)/).captures lineno = lineno.to_i absolute_path = File.(file_path) source_map = @source_map_provider.for_file_path(absolute_path) return location unless source_map line_number = source_map.line(lineno) || '?' location.gsub(/#{ASTTransform.output_path}\/([\S]+):(\d+)/, "\\1:#{line_number}") end |