Class: RSpec::Signal::Group

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

Overview

A set of failures that share a fingerprint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fingerprint:, first_seen:) ⇒ Group

Returns a new instance of Group.



9
10
11
12
13
# File 'lib/rspec/signal/group.rb', line 9

def initialize(fingerprint:, first_seen:)
  @fingerprint = fingerprint
  @first_seen = first_seen
  @failures = []
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures.



7
8
9
# File 'lib/rspec/signal/group.rb', line 7

def failures
  @failures
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



7
8
9
# File 'lib/rspec/signal/group.rb', line 7

def fingerprint
  @fingerprint
end

#first_seenObject (readonly)

Returns the value of attribute first_seen.



7
8
9
# File 'lib/rspec/signal/group.rb', line 7

def first_seen
  @first_seen
end

Instance Method Details

#<<(failure) ⇒ Object



15
16
17
18
# File 'lib/rspec/signal/group.rb', line 15

def <<(failure)
  @failures << failure
  self
end

#affected_locationsObject

Locations of every example in the group, in run order, deduplicated.



42
43
44
# File 'lib/rspec/signal/group.rb', line 42

def affected_locations
  @affected_locations ||= @failures.map(&:spec_location).uniq
end

#exception_classObject



33
34
35
# File 'lib/rspec/signal/group.rb', line 33

def exception_class
  representative.exception_class
end

#messageObject



37
38
39
# File 'lib/rspec/signal/group.rb', line 37

def message
  representative.message
end

#omitted_framesObject

Total backtrace frames this group's failures dropped.



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

def omitted_frames
  @failures.sum { |failure| failure.reduced.omitted_count }
end

#othersObject



46
47
48
# File 'lib/rspec/signal/group.rb', line 46

def others
  @failures.reject { |failure| failure.equal?(representative) }
end

#representativeObject

The failure shown in full. We pick the one carrying the most first-party frames, because that is the one whose trace is most useful; ties break on run order so the choice is stable across runs.



27
28
29
30
31
# File 'lib/rspec/signal/group.rb', line 27

def representative
  @representative ||= @failures.each_with_index.max_by do |failure, index|
    [failure.reduced.project_frames.size, failure.reduced.kept_count, -index]
  end.first
end

#sizeObject



20
21
22
# File 'lib/rspec/signal/group.rb', line 20

def size
  @failures.size
end

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rspec/signal/group.rb', line 55

def to_h
  {
    signature: fingerprint.digest,
    count: size,
    exception: exception_class,
    culprit: fingerprint.culprit,
    app_context: fingerprint.app_context,
    representative: representative.to_h,
    affected: @failures.map { |failure| { location: failure.spec_location, description: failure.description } }
  }.compact
end