Class: RSpec::Core::BacktraceFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBacktraceFormatter

Returns a new instance of BacktraceFormatter.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 8

def initialize
  @full_backtrace = false

  patterns = %w[ /lib\d*/ruby/ bin/ exe/rspec /lib/bundler/ /exe/bundle: ]
  patterns << "org/jruby/" if RUBY_PLATFORM == 'java'
  patterns.map! { |s| Regexp.new(s.gsub("/", File::SEPARATOR)) }

  @exclusion_patterns = [Regexp.union(RSpec::CallerFilter::IGNORE_REGEX, *patterns)]
  @inclusion_patterns = []

  return unless matches?(@exclusion_patterns, File.join(Dir.getwd, "lib", "foo.rb:13"))
  inclusion_patterns << Regexp.new(Dir.getwd)
end

Instance Attribute Details

#exclusion_patternsObject



6
7
8
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 6

def exclusion_patterns
  @exclusion_patterns
end

#full_backtrace=(value) ⇒ Object (writeonly)

Sets the attribute full_backtrace

Parameters:

  • value

    the value to set the attribute full_backtrace to.



22
23
24
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 22

def full_backtrace=(value)
  @full_backtrace = value
end

#inclusion_patternsObject



6
7
8
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 6

def inclusion_patterns
  @inclusion_patterns
end

Instance Method Details

#backtrace_line(line) ⇒ Object



49
50
51
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 49

def backtrace_line(line)
  Metadata.relative_path(line) unless exclude?(line)
end

#exclude?(line) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 53

def exclude?(line)
  return false if @full_backtrace
  matches?(exclusion_patterns, line) && !matches?(inclusion_patterns, line)
end

#filter_gem(gem_name) ⇒ Object



28
29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 28

def filter_gem(gem_name)
  sep = File::SEPARATOR
  exclusion_patterns << /#{sep}#{gem_name}(-[^#{sep}]+)?#{sep}/
end

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 33

def format_backtrace(backtrace, options={})
  return [] unless backtrace
  return backtrace if options[:full_backtrace] || backtrace.empty?

  backtrace.map { |l| backtrace_line(l) }.compact.
    tap do |filtered|
      if filtered.empty?
        filtered.concat backtrace
        filtered << ""
        filtered << "  Showing full backtrace because every line was filtered out."
        filtered << "  See docs for RSpec::Configuration#backtrace_exclusion_patterns and"
        filtered << "  RSpec::Configuration#backtrace_inclusion_patterns for more information."
      end
    end
end

#full_backtrace?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/backtrace_formatter.rb', line 24

def full_backtrace?
  @full_backtrace || exclusion_patterns.empty?
end