Class: RSpec::Signal::Cluster
- Inherits:
-
Object
- Object
- RSpec::Signal::Cluster
- Defined in:
- lib/rspec/signal/cluster.rb
Overview
A set of failures that share one diagnostic symptom.
Weaker than a Group on purpose. A group asserts that its failures are the same failure; a cluster asserts only that they share a strong symptom and are worth looking at together. The report says so in those words, so nothing downstream mistakes one for the other.
Defined Under Namespace
Classes: Member
Instance Attribute Summary collapse
-
#first_seen ⇒ Object
readonly
Returns the value of attribute first_seen.
-
#symptom ⇒ Object
readonly
Returns the value of attribute symptom.
Instance Method Summary collapse
- #add(failure, symptom) ⇒ Object
- #failures ⇒ Object
-
#initialize(symptom:, first_seen:) ⇒ Cluster
constructor
A new instance of Cluster.
- #key ⇒ Object
- #kind ⇒ Object
- #label ⇒ Object
- #signature_count ⇒ Object
-
#signatures ⇒ Object
The exact signatures this cluster spans.
- #size ⇒ Object
- #spec_files ⇒ Object
-
#symptom_counts ⇒ Object
The distinct wordings the symptom took, most common first, ties broken by the order they were seen so the list is stable.
- #to_h ⇒ Object
Constructor Details
#initialize(symptom:, first_seen:) ⇒ Cluster
Returns a new instance of Cluster.
16 17 18 19 20 |
# File 'lib/rspec/signal/cluster.rb', line 16 def initialize(symptom:, first_seen:) @symptom = symptom @first_seen = first_seen @members = [] end |
Instance Attribute Details
#first_seen ⇒ Object (readonly)
Returns the value of attribute first_seen.
14 15 16 |
# File 'lib/rspec/signal/cluster.rb', line 14 def first_seen @first_seen end |
#symptom ⇒ Object (readonly)
Returns the value of attribute symptom.
14 15 16 |
# File 'lib/rspec/signal/cluster.rb', line 14 def symptom @symptom end |
Instance Method Details
#add(failure, symptom) ⇒ Object
22 23 24 25 |
# File 'lib/rspec/signal/cluster.rb', line 22 def add(failure, symptom) @members << Member.new(failure, symptom.detail) self end |
#failures ⇒ Object
27 28 29 |
# File 'lib/rspec/signal/cluster.rb', line 27 def failures @members.map(&:failure) end |
#key ⇒ Object
39 40 41 |
# File 'lib/rspec/signal/cluster.rb', line 39 def key @symptom.key end |
#kind ⇒ Object
35 36 37 |
# File 'lib/rspec/signal/cluster.rb', line 35 def kind @symptom.kind end |
#label ⇒ Object
43 44 45 |
# File 'lib/rspec/signal/cluster.rb', line 43 def label @symptom.label end |
#signature_count ⇒ Object
63 64 65 |
# File 'lib/rspec/signal/cluster.rb', line 63 def signature_count signatures.size end |
#signatures ⇒ Object
The exact signatures this cluster spans. More than one is what makes a cluster worth printing at all.
59 60 61 |
# File 'lib/rspec/signal/cluster.rb', line 59 def signatures @signatures ||= failures.map { |failure| failure.fingerprint.digest }.uniq end |
#size ⇒ Object
31 32 33 |
# File 'lib/rspec/signal/cluster.rb', line 31 def size @members.size end |
#spec_files ⇒ Object
67 68 69 |
# File 'lib/rspec/signal/cluster.rb', line 67 def spec_files @spec_files ||= failures.map { |failure| failure.spec_location.sub(/:\d+\z/, "") }.uniq end |
#symptom_counts ⇒ Object
The distinct wordings the symptom took, most common first, ties broken by the order they were seen so the list is stable.
49 50 51 52 53 54 55 |
# File 'lib/rspec/signal/cluster.rb', line 49 def symptom_counts @symptom_counts ||= begin counts = @members.each_with_object(Hash.new(0)) { |member, tally| tally[member.detail] += 1 } seen = counts.keys.each_with_index.to_h counts.sort_by { |detail, count| [-count, seen[detail]] }.to_h end end |
#to_h ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rspec/signal/cluster.rb', line 71 def to_h { kind: kind, key: key, label: label, count: size, signatures: signatures, symptoms: symptom_counts, specs: spec_files } end |