Class: FlakeySpecCatcher::RspecResultManager

Inherits:
Object
  • Object
show all
Defined in:
lib/flakey_spec_catcher/rspec_result_manager.rb

Overview

RspecResultManager class

Holds a collection of RSpec results and provides helper methods

An RspecResultManager will hold a collection of results, one for each distinct example. It also provides helpers for adding new results, displaying aggregate results, and checking the state of the collection.

Instance Method Summary collapse

Constructor Details

#initialize(rspec_result_class) ⇒ RspecResultManager

Returns a new instance of RspecResultManager.



15
16
17
18
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 15

def initialize(rspec_result_class)
  @result_class = rspec_result_class
  @results = []
end

Instance Method Details

#add_result(desc, location, message = nil) ⇒ Object



20
21
22
23
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 20

def add_result(desc, location, message = nil)
  result = @results.find { |r| r.location == location }
  result ? result.add_run(message) : @results.push(@result_class.new(desc, location, message))
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 39

def empty?
  @results.empty?
end

#failuresObject



31
32
33
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 31

def failures
  @results.select { |r| r.total_failures.positive? }
end


25
26
27
28
29
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 25

def print_results
  puts "\n********** SUMMARY **********"
  print_successes_count(successes)
  failures.each(&:print_results) if failures.any?
end

#successesObject



35
36
37
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 35

def successes
  @results.select { |r| r.total_failures.zero? }
end