Class: FlakeySpecCatcher::RspecResult::RSpecFailure

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

Overview

Simple class to contain failed example data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception_message, spec_start_time = nil) ⇒ RSpecFailure

Returns a new instance of RSpecFailure.



61
62
63
64
65
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 61

def initialize(exception_message, spec_start_time = nil)
  @exception_message = exception_message
  @count = 1
  @spec_start_times = [spec_start_time].compact
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



59
60
61
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 59

def count
  @count
end

#exception_messageObject (readonly)

Returns the value of attribute exception_message.



59
60
61
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 59

def exception_message
  @exception_message
end

#spec_start_timesObject (readonly)

Returns the value of attribute spec_start_times.



59
60
61
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 59

def spec_start_times
  @spec_start_times
end

Instance Method Details

#add_failure(spec_start_time = nil) ⇒ Object



67
68
69
70
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 67

def add_failure(spec_start_time = nil)
  @count += 1
  @spec_start_times.push(spec_start_time) unless spec_start_time.nil?
end

#failure_summaryObject



72
73
74
75
76
77
78
79
80
# File 'lib/flakey_spec_catcher/rspec_result.rb', line 72

def failure_summary
  summary = "#{count.to_s.indent(2)} times with exception message:\n"
  summary += exception_message.indent(4).red.to_s
  return summary if spec_start_times.empty?

  summary += "\n\nFailed at the following times:\n".indent(2)
  summary += spec_start_times.map { |time| time.indent(4).yellow.to_s }.join("\n").to_s
  summary
end