Class: RSpec::Core::BacktraceFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/provider/rspec/backtrace_formatter.rb

Overview

RSpec 3 has a hardwired @system_exclusion_patterns which removes everything matching /bin// This causes all the backtrace lines to be cleaned, as rake pact:verify now shells out to the executable ‘pact verify …` which then causes all the lines to be included as the BacktraceFormatter will include all lines of the backtrace if all lines were filtered out. This monkey patch only shows lines including bin/pact and removes the “show all lines if no lines would otherwise be shown” logic.

Instance Method Summary collapse

Instance Method Details

#backtrace_line(line) ⇒ Object



20
21
22
23
24
# File 'lib/pact/provider/rspec/backtrace_formatter.rb', line 20

def backtrace_line(line)
  relative_path(line) unless exclude?(line)
rescue SecurityError
  nil
end

#exclude?(line) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/pact/provider/rspec/backtrace_formatter.rb', line 26

def exclude?(line)
  return false if @full_backtrace
  relative_line = relative_path(line)
  return true unless /bin\/pact/ =~ relative_line
end

#format_backtrace(backtrace, options = {}) ⇒ Object



15
16
17
18
# File 'lib/pact/provider/rspec/backtrace_formatter.rb', line 15

def format_backtrace(backtrace, options = {})
  return backtrace if options[:full_backtrace]
  backtrace.map { |l| backtrace_line(l) }.compact
end

#relative_path(line) ⇒ Object

Copied from Metadata so a refactor can’t break this overridden class



33
34
35
36
37
38
39
40
# File 'lib/pact/provider/rspec/backtrace_formatter.rb', line 33

def relative_path(line)
  line = line.sub(File.expand_path("."), ".")
  line = line.sub(/\A([^:]+:\d+)$/, '\\1')
  return nil if line == '-e:1'
  line
rescue SecurityError
  nil
end