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
# File 'lib/rspec/signal/cluster.rb', line 27

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

#keyObject



30
# File 'lib/rspec/signal/cluster.rb', line 30

def key      = @symptom.key

#kindObject



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

def kind     = @symptom.kind

#labelObject



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

def label    = @symptom.label

#signature_countObject



49
# File 'lib/rspec/signal/cluster.rb', line 49

def signature_count = signatures.size

#signaturesObject

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

#sizeObject



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

def size     = @members.size

#spec_filesObject



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_countsObject

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_hObject



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