Class: RSpec::Signal::Report

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

Overview

The complete, renderer-independent result of a run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(failures:, example_count: 0, failure_count: nil, pending_count: 0, duration: nil, seed: nil, seed_used: false, environment: {}, errors_outside_examples: 0, relate_failures: true) ⇒ Report

Returns a new instance of Report.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rspec/signal/report.rb', line 10

def initialize(failures:, example_count: 0, failure_count: nil, pending_count: 0,
               duration: nil, seed: nil, seed_used: false, environment: {},
               errors_outside_examples: 0, relate_failures: true)
  @failures = failures
  @groups = Grouper.call(failures)
  @clusters = relate_failures ? safely { Clusterer.call(failures) } : []
  @example_count = example_count
  @failure_count = failure_count || failures.size
  @pending_count = pending_count
  @duration = duration
  @seed = seed
  @seed_used = seed_used
  @environment = environment
  @errors_outside_examples = errors_outside_examples
end

Instance Attribute Details

#clustersObject (readonly)

Returns the value of attribute clusters.



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

def clusters
  @clusters
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#environmentObject (readonly)

Returns the value of attribute environment.



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

def environment
  @environment
end

#errors_outside_examplesObject (readonly)

Returns the value of attribute errors_outside_examples.



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

def errors_outside_examples
  @errors_outside_examples
end

#example_countObject (readonly)

Returns the value of attribute example_count.



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

def example_count
  @example_count
end

#failure_countObject (readonly)

Returns the value of attribute failure_count.



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

def failure_count
  @failure_count
end

#failuresObject (readonly)

Returns the value of attribute failures.



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

def failures
  @failures
end

#groupsObject (readonly)

Returns the value of attribute groups.



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

def groups
  @groups
end

#pending_countObject (readonly)

Returns the value of attribute pending_count.



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

def pending_count
  @pending_count
end

#seedObject (readonly)

Returns the value of attribute seed.



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

def seed
  @seed
end

#seed_usedObject (readonly)

Returns the value of attribute seed_used.



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

def seed_used
  @seed_used
end

Instance Method Details

#any_failures?Boolean

Returns:

  • (Boolean)


36
# File 'lib/rspec/signal/report.rb', line 36

def any_failures? = !failures.empty?

#cluster_countObject



35
# File 'lib/rspec/signal/report.rb', line 35

def cluster_count = clusters.size

#group_countObject



34
# File 'lib/rspec/signal/report.rb', line 34

def group_count   = groups.size

#kept_framesObject



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

def kept_frames = total_frames - omitted_frames

#omitted_framesObject

Backtrace frames dropped across the whole run. This is the number that makes the reduction visible.



41
42
43
# File 'lib/rspec/signal/report.rb', line 41

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

#safelyObject

Clustering is the newest and least essential stage; a report without it is still worth having, so it is never allowed to take the run down.



28
29
30
31
32
# File 'lib/rspec/signal/report.rb', line 28

def safely
  yield
rescue StandardError
  []
end

#seed_used?Boolean

Returns:

  • (Boolean)


37
# File 'lib/rspec/signal/report.rb', line 37

def seed_used? = !!@seed_used

#to_hObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rspec/signal/report.rb', line 51

def to_h
  {
    schema: 1,
    generated_by: "rspec-signal #{VERSION}",
    summary: {
      examples: example_count,
      failures: failure_count,
      pending: pending_count,
      signatures: group_count,
      related_clusters: cluster_count.positive? ? cluster_count : nil,
      duration_seconds: duration&.round(3),
      seed: seed_used? ? seed : nil,
      errors_outside_examples: errors_outside_examples.positive? ? errors_outside_examples : nil
    }.compact,
    environment: environment,
    backtrace_reduction: { total_frames: total_frames, kept_frames: kept_frames, omitted_frames: omitted_frames },
    signatures: groups.map(&:to_h),
    related: clusters.map(&:to_h)
  }
end

#total_framesObject



45
46
47
# File 'lib/rspec/signal/report.rb', line 45

def total_frames
  @total_frames ||= failures.sum { |failure| failure.reduced.total }
end

#worker_h(write_full: false) ⇒ Object

Worker interchange data. Unlike the public report summary this retains every reduced failure so grouping can be repeated across all workers.

raw -- the unreduced formatter output -- is included only when write_full is on, since it is otherwise discarded on merge and would just bloat every worker payload for no reason.



78
79
80
81
82
83
84
85
# File 'lib/rspec/signal/report.rb', line 78

def worker_h(write_full: false)
  serialized = failures.map do |failure|
    attributes = failure.to_h.merge(fingerprint: failure.fingerprint.to_h)
    attributes[:raw] = failure.raw if write_full
    attributes
  end
  to_h.merge(schema: 2, failures: serialized)
end