class FlakyTester::TestRunner

Public Class Methods

new(command_options) click to toggle source
# File lib/flaky_tester/test_runner.rb, line 7
def initialize(command_options)
  @command_options = command_options
  @results_file = build_results_file
end

Public Instance Methods

run() click to toggle source
# File lib/flaky_tester/test_runner.rb, line 12
def run
  total_runs = @command_options[:times]

  for current_run in (1..total_runs)
    print("Running #{current_run}/#{total_runs}...\r")

    command_succeeded = system(command)

    raise(Errors::RspecError) unless command_succeeded
  end

  @results_file
end

Private Instance Methods

build_results_file() click to toggle source
# File lib/flaky_tester/test_runner.rb, line 28
def build_results_file
  dir_name = "tmp"
  dir_path = File.join(Dir.pwd, dir_name)

  file_name = "fspec@#{Time.now.strftime("%Y%m%d%H%M%S")}.txt"
  file_path = File.join(Dir.pwd, dir_name, file_name)

  FileUtils.mkpath(dir_path)
  File.new(file_path, "w+")
end
command() click to toggle source
# File lib/flaky_tester/test_runner.rb, line 39
def command
  "#{rspec_command} >> \"#{@results_file.path}\""
end
rspec_command() click to toggle source
# File lib/flaky_tester/test_runner.rb, line 43
def rspec_command
  "bundle exec rspec --no-fail-fast --format progress --profile 0 --failure-exit-code 0 #{@command_options[:path]}"
end