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 |
# File 'lib/rspec/signal/cluster.rb', line 27 def failures = @members.map(&:failure) |
#key ⇒ Object
30 |
# File 'lib/rspec/signal/cluster.rb', line 30 def key = @symptom.key |
#kind ⇒ Object
29 |
# File 'lib/rspec/signal/cluster.rb', line 29 def kind = @symptom.kind |
#label ⇒ Object
31 |
# File 'lib/rspec/signal/cluster.rb', line 31 def label = @symptom.label |
#signature_count ⇒ Object
49 |
# File 'lib/rspec/signal/cluster.rb', line 49 def signature_count = signatures.size |
#signatures ⇒ Object
The exact signatures this cluster spans. More than one is what makes a cluster worth printing at all.
45 46 47 |
# File 'lib/rspec/signal/cluster.rb', line 45 def signatures @signatures ||= failures.map { |failure| failure.fingerprint.digest }.uniq end |
#size ⇒ Object
28 |
# File 'lib/rspec/signal/cluster.rb', line 28 def size = @members.size |
#spec_files ⇒ Object
51 52 53 |
# File 'lib/rspec/signal/cluster.rb', line 51 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.
35 36 37 38 39 40 41 |
# File 'lib/rspec/signal/cluster.rb', line 35 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
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rspec/signal/cluster.rb', line 55 def to_h { kind: kind, key: key, label: label, count: size, signatures: signatures, symptoms: symptom_counts, specs: spec_files } end |