Class: RSpec::Signal::Cluster

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_seenObject (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

#symptomObject (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

#failuresObject



27
28
29
# File 'lib/rspec/signal/cluster.rb', line 27

def failures
  @members.map(&:failure)
end

#keyObject



39
40
41
# File 'lib/rspec/signal/cluster.rb', line 39

def key
  @symptom.key
end

#kindObject



35
36
37
# File 'lib/rspec/signal/cluster.rb', line 35

def kind
  @symptom.kind
end

#labelObject



43
44
45
# File 'lib/rspec/signal/cluster.rb', line 43

def label
  @symptom.label
end

#signature_countObject



63
64
65
# File 'lib/rspec/signal/cluster.rb', line 63

def signature_count
  signatures.size
end

#signaturesObject

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

#sizeObject



31
32
33
# File 'lib/rspec/signal/cluster.rb', line 31

def size
  @members.size
end

#spec_filesObject



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_countsObject

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_hObject



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