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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rspec_result_class) ⇒ RspecResultManager

Returns a new instance of RspecResultManager.



17
18
19
20
21
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 17

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

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



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

def results
  @results
end

Instance Method Details

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



27
28
29
30
31
32
33
34
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 27

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

#empty?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 50

def empty?
  @results.empty?
end

#failuresObject



42
43
44
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 42

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


36
37
38
39
40
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 36

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

#successesObject



46
47
48
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 46

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

#track_spec_start_times(spec_times) ⇒ Object



23
24
25
# File 'lib/flakey_spec_catcher/rspec_result_manager.rb', line 23

def track_spec_start_times(spec_times)
  @spec_start_times = spec_times
end