Class: FlakeySpecCatcher::RspecResult

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

Overview

RspecResult class

Organizes results for a changed test (spec).

Each changed test will have one RspecResult created for it and for each re-run of that spec, the results will be pushed to the RspecResult object. This class will then organize and output the results accordingly.

Defined Under Namespace

Classes: RSpecFailure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, location, spec_start_times, exception_message = nil) ⇒ RspecResult

Returns a new instance of RspecResult.



18
19
20
21
22
23
24
25
26
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 18

def initialize(description, location, spec_start_times, exception_message = nil)
  @description = description
  @location = location
  @total_times_run = 1
  @total_failures = exception_message ? 1 : 0
  @failures = []
  @spec_start_times = spec_start_times
  add_failure(exception_message) if exception_message
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#failuresObject (readonly)

Returns the value of attribute failures.



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

def failures
  @failures
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#spec_start_timesObject (readonly)

Returns the value of attribute spec_start_times.



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

def spec_start_times
  @spec_start_times
end

#total_failuresObject

Returns the value of attribute total_failures.



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

def total_failures
  @total_failures
end

#total_times_runObject

Returns the value of attribute total_times_run.



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

def total_times_run
  @total_times_run
end

Instance Method Details

#add_failure(exception_message) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 37

def add_failure(exception_message)
  failure = @failures.find { |f| f.exception_message == exception_message }
  if failure
    failure.add_failure(current_spec_start_time)
  else
    @failures.push(RSpecFailure.new(exception_message, current_spec_start_time))
  end
end

#add_run(exception_message = nil) ⇒ Object



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

def add_run(exception_message = nil)
  @total_times_run += 1

  return unless exception_message

  @total_failures += 1
  add_failure(exception_message)
end

#current_spec_start_timeObject



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

def current_spec_start_time
  @spec_start_times[@total_times_run - 1]
end


50
51
52
53
54
55
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 50

def print_results
  puts "\n#{@description.yellow} (#{location})
        \nFAILED #{total_failures} / #{total_times_run} times"

  @failures.each { |failure| puts failure.failure_summary }
end