class RspecN::Run

Attributes

duration_seconds[RW]
finish_time[RW]
iteration[RW]
result_count_string[RW]
rspec_status[RW]
rspec_stderr[RW]
rspec_stdout[RW]
seed[RW]
start_time[RW]
status_string[RW]

Public Class Methods

new(iteration:) click to toggle source
# File lib/rspec_n/run.rb, line 6
def initialize(iteration:)
  @duration_seconds = nil
  @finish_time = nil
  @has_warnings = nil
  @iteration = iteration
  @result_count_string = nil
  @rspec_stdout = nil
  @rspec_stderr = nil
  @rspec_status = nil
  @seed = nil
  @skipped = false
  @status_string = nil
  @start_time = nil
end

Public Instance Methods

failed?() click to toggle source
# File lib/rspec_n/run.rb, line 63
def failed?
  @status_string == "Fail"
end
formatted_finish_time(format) click to toggle source
# File lib/rspec_n/run.rb, line 42
def formatted_finish_time(format)
  finish_time.strftime(format)
end
formatted_start_time(format) click to toggle source
# File lib/rspec_n/run.rb, line 38
def formatted_start_time(format)
  start_time.strftime(format)
end
go(command) click to toggle source
# File lib/rspec_n/run.rb, line 34
def go(command)
  @rspec_stdout, @rspec_stderr, @rspec_status = Open3.capture3(command)
end
has_warnings?() click to toggle source
# File lib/rspec_n/run.rb, line 46
def has_warnings?
  @has_warnings
end
passed?() click to toggle source
# File lib/rspec_n/run.rb, line 50
def passed?
  @status_string == "Pass"
end
skip() click to toggle source
# File lib/rspec_n/run.rb, line 54
def skip
  @skipped = true
  @duration_seconds = 0
end
skipped?() click to toggle source
# File lib/rspec_n/run.rb, line 59
def skipped?
  @skipped
end
start_clock() click to toggle source
# File lib/rspec_n/run.rb, line 21
def start_clock
  @start_time = Time.now
end
stop_clock() click to toggle source
# File lib/rspec_n/run.rb, line 25
def stop_clock
  @finish_time = Time.now
  finalize_duration_seconds
  finalize_seed
  finalize_status_string
  finalize_result_count_string
  finalize_has_warnings
end

Private Instance Methods

finalize_duration_seconds() click to toggle source
# File lib/rspec_n/run.rb, line 69
def finalize_duration_seconds
  @duration_seconds = (@finish_time - @start_time).round
end
finalize_has_warnings() click to toggle source
# File lib/rspec_n/run.rb, line 95
def finalize_has_warnings
  @has_warnings = @rspec_status.exitstatus.zero? && !@rspec_stderr.empty?
end
finalize_result_count_string() click to toggle source

rubocop:enable Style/NegatedIf

# File lib/rspec_n/run.rb, line 90
def finalize_result_count_string
  result = @rspec_stdout.match(/\d*\s+examples?,\s+\d*\s+failures?(,\s+\d*\s+pending)*/)
  @result_count_string = result ? result.to_s : ""
end
finalize_seed() click to toggle source
# File lib/rspec_n/run.rb, line 73
def finalize_seed
  result = @rspec_stdout.match(/^Randomized with seed (\d*)/)
  return if result.nil? # A seed wasn't used

  @seed = result.captures.first&.strip
end
finalize_status_string() click to toggle source

rubocop:disable Style/NegatedIf

# File lib/rspec_n/run.rb, line 81
def finalize_status_string
  return @status_string = "Skip" if skipped?
  return @status_string = "Pass" if @rspec_status.exitstatus.zero?
  return @status_string = "Fail" if !@rspec_status.exitstatus.zero?

  @status_string = "Undetermined"
end