Class: RSpec::Signal::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/signal/failure.rb

Overview

One failed example, normalized and reduced. Pure data -- it knows nothing about RSpec, so every downstream stage is trivially testable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description:, spec_location:, exception_class:, message:, reduced:, frames:, rerun: nil, example_id: nil, diagnostics: {}, shared_group_locations: [], raw: nil, fingerprint: nil) ⇒ Failure

Returns a new instance of Failure.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rspec/signal/failure.rb', line 12

def initialize(description:, spec_location:, exception_class:, message:, reduced:, frames:,
               rerun: nil, example_id: nil, diagnostics: {}, shared_group_locations: [],
               raw: nil, fingerprint: nil)
  @description = description
  @spec_location = spec_location
  @exception_class = exception_class
  @message = message
  @reduced = reduced
  @frames = frames
  @rerun = rerun || spec_location
  @example_id = example_id
  @diagnostics = diagnostics
  @shared_group_locations = shared_group_locations
  @raw = raw
  @fingerprint = fingerprint
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def description
  @description
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def diagnostics
  @diagnostics
end

#example_idObject (readonly)

Returns the value of attribute example_id.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def example_id
  @example_id
end

#exception_classObject (readonly)

Returns the value of attribute exception_class.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def exception_class
  @exception_class
end

#framesObject (readonly)

Returns the value of attribute frames.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def frames
  @frames
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def message
  @message
end

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def raw
  @raw
end

#reducedObject (readonly)

Returns the value of attribute reduced.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def reduced
  @reduced
end

#rerunObject (readonly)

Returns the value of attribute rerun.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def rerun
  @rerun
end

#shared_group_locationsObject (readonly)

Returns the value of attribute shared_group_locations.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def shared_group_locations
  @shared_group_locations
end

#spec_locationObject (readonly)

Returns the value of attribute spec_location.



8
9
10
# File 'lib/rspec/signal/failure.rb', line 8

def spec_location
  @spec_location
end

Instance Method Details

#fingerprintObject



29
30
31
32
33
34
35
36
# File 'lib/rspec/signal/failure.rb', line 29

def fingerprint
  @fingerprint ||= Fingerprint.for(
    exception_class: exception_class,
    message: message.normalized,
    frames: frames,
    fallback_location: spec_location
  )
end

#symptomObject

The one diagnostic characteristic this failure clusters on, if any. nil is the common and safe answer.



40
41
42
43
44
# File 'lib/rspec/signal/failure.rb', line 40

def symptom
  return @symptom if defined?(@symptom)

  @symptom = Symptoms.for(self)
end

#to_hObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rspec/signal/failure.rb', line 46

def to_h
  {
    description: description,
    location: spec_location,
    rerun: rerun,
    id: example_id,
    exception: exception_class,
    message: message.body,
    trace: reduced.entries.map(&:to_h),
    omitted_frames: reduced.omitted_count,
    diagnostics: diagnostics,
    symptom: symptom&.to_h
  }.reject { |_, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) }
end