Class: RSpec::Signal::Fingerprint

Inherits:
Struct
  • Object
show all
Defined in:
lib/rspec/signal/fingerprint.rb,
lib/rspec/signal/fingerprint.rb

Overview

Construction and rendering for the fingerprint value object above.

Constant Summary collapse

DEFAULT_SPEC_PATTERNS =

Constants inside a Struct.new block would land on the enclosing module, so define this one explicitly.

[%r{\Aspec/}, %r{\Atest/}, /_spec\.rb\z/, /_test\.rb\z/].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_contextObject

Returns the value of attribute app_context

Returns:

  • (Object)

    the current value of app_context



22
23
24
# File 'lib/rspec/signal/fingerprint.rb', line 22

def app_context
  @app_context
end

#culpritObject

Returns the value of attribute culprit

Returns:

  • (Object)

    the current value of culprit



22
23
24
# File 'lib/rspec/signal/fingerprint.rb', line 22

def culprit
  @culprit
end

#exception_classObject

Returns the value of attribute exception_class

Returns:

  • (Object)

    the current value of exception_class



22
23
24
# File 'lib/rspec/signal/fingerprint.rb', line 22

def exception_class
  @exception_class
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



22
23
24
# File 'lib/rspec/signal/fingerprint.rb', line 22

def message
  @message
end

Class Method Details

.for(exception_class:, message:, frames:, fallback_location:, spec_patterns: DEFAULT_SPEC_PATTERNS) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rspec/signal/fingerprint.rb', line 30

def self.for(exception_class:, message:, frames:, fallback_location:, spec_patterns: DEFAULT_SPEC_PATTERNS)
  significant = frames.reject(&:framework?)
  culprit = significant.first
  app_context = significant.find do |frame|
    frame.project? && spec_patterns.none? { |pattern| pattern.match?(frame.display_path) }
  end

  new(
    exception_class: exception_class.to_s,
    message: message.to_s,
    culprit: culprit&.location || fallback_location,
    app_context: app_context&.location
  )
end

Instance Method Details

#digestObject

Joined on NUL so that shifting text from one component into the next cannot produce the same digest.



47
48
49
# File 'lib/rspec/signal/fingerprint.rb', line 47

def digest
  @digest ||= Digest::SHA256.hexdigest(to_a.join("\0"))[0, 12]
end

#to_hObject



51
52
53
# File 'lib/rspec/signal/fingerprint.rb', line 51

def to_h
  { exception: exception_class, culprit: culprit, app_context: app_context, digest: digest }.compact
end