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, exception_message = nil) ⇒ RspecResult

Returns a new instance of RspecResult.



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

def initialize(description, location, exception_message = nil)
  @description = description
  @location = location
  @total_times_run = 1
  @total_failures = exception_message ? 1 : 0
  @failures = []
  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

#locationObject

Returns the value of attribute location.



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

def location
  @location
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



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

def add_failure(exception_message)
  failure = @failures.find { |f| f.exception_message == exception_message }
  failure ? failure.add_failure : @failures.push(RSpecFailure.new(exception_message))
end

#add_run(exception_message = nil) ⇒ Object



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

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

  return unless exception_message

  @total_failures += 1
  add_failure(exception_message)
end


40
41
42
43
44
45
46
47
48
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 40

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

  @failures.each do |f|
    puts "#{f.count.to_s.indent(2)} times with exception message:"
    puts f.exception_message.indent(4).red.to_s
  end
end