class FlakeySpecCatcher::Runner
Attributes
git_controller[R]
rerun_manager[R]
test_run_count[R]
user_config[R]
Public Class Methods
new(test_mode: false, user_config: FlakeySpecCatcher::UserConfig.new, git_controller: FlakeySpecCatcher::GitController.new(test_mode: test_mode, user_config: user_config), result_manager: FlakeySpecCatcher::RspecResultManager.new(FlakeySpecCatcher::RspecResult), rerun_manager: FlakeySpecCatcher::RerunManager.new(git_controller: git_controller, user_config: user_config))
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 15 def initialize(test_mode: false, user_config: FlakeySpecCatcher::UserConfig.new, git_controller: FlakeySpecCatcher::GitController.new(test_mode: test_mode, user_config: user_config), result_manager: FlakeySpecCatcher::RspecResultManager.new(FlakeySpecCatcher::RspecResult), rerun_manager: FlakeySpecCatcher::RerunManager.new(git_controller: git_controller, user_config: user_config)) @git_controller = git_controller @user_config = user_config @rerun_manager = rerun_manager @rspec_result_manager = result_manager @test_run_count = 0 @temp_output_file = @user_config.output_file + 'temp' unless @user_config.output_file == File::NULL end
Public Instance Methods
rerun_preview()
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/flakey_spec_catcher/runner.rb, line 49 def rerun_preview puts "\n********************************************" puts "Re-run Preview\n" @rerun_manager.rerun_capsules.each do |capsule| capsule.testcase.each do |test| rerun_msg = " Running #{test} #{@user_config.repeat_factor} times " rerun_msg += "using `#{capsule.usage}`" unless capsule.default_usage? puts rerun_msg end end puts "\n********************************************" end
run_specs()
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 71 def run_specs return 0 if @user_config.dry_run status = 0 @rerun_manager.rerun_capsules.sort.each do |capsule| @user_config.repeat_factor.times do iteration_status = handle_capsule_rerun(capsule) status = [status, iteration_status].max break if @user_config.break_on_first_failure && !status.zero? end end display_results(status) copy_to_user_output unless @user_config.output_file == File::NULL # Always return 0 if silent_mode is enabled @user_config.silent_mode ? 0 : status end
show_settings()
click to toggle source
Debug Methods rubocop:disable Metrics/AbcSize
# File lib/flakey_spec_catcher/runner.rb, line 32 def show_settings puts 'Flakey Spec Catcher Settings:' puts " Current Branch: #{@git_controller.branch}" unless @user_config.use_parent puts " Remote: #{@git_controller.remote}" unless @user_config.use_parent puts " Current Sha: #{@git_controller.working_commit_sha}" puts " Base Sha: #{@git_controller.base_commit_sha}" puts " Repeat factor: #{@user_config.repeat_factor}" puts " Break on first failure: #{@user_config.break_on_first_failure}" if @user_config.break_on_first_failure puts " Node Total: #{@user_config.split_nodes}" if @user_config.split_nodes puts " Node Index: #{@user_config.split_index}" if @user_config.split_index puts " Changed Specs Detected: #{@git_controller.changed_examples}" return if @user_config.output_file == File::NULL puts " Verbose Output Path: #{@user_config.output_file}" end
show_test_list()
click to toggle source
end Debug methods
# File lib/flakey_spec_catcher/runner.rb, line 63 def show_test_list @rerun_manager.rerun_capsules.each do |capsule| capsule.testcase.each do |test| puts test end end end
Private Instance Methods
configure_listener()
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 142 def configure_listener RSpec.configure do |c| c.reporter.register_listener EventListener.new(@rspec_result_manager), :example_failed, :example_passed end end
copy_output_to_temp_file()
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 149 def copy_output_to_temp_file # copy contents of output file, it will get overwritten in RSpec::Core::Runner File.open(@temp_output_file, 'a') do |f| f.puts IO.readlines(@user_config.output_file) end end
copy_to_user_output()
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 156 def copy_to_user_output # copy all appended output to original output file, delete the temp output file IO.copy_stream(@temp_output_file, @user_config.output_file) if File.exist?(@temp_output_file) File.delete(@temp_output_file) if File.exist?(@temp_output_file) end
display_results(status)
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 92 def display_results(status) @rspec_result_manager.print_results unless @rspec_result_manager.empty? status.zero? ? print_no_flakey_specs_detected_message : print_flakey_specs_detected_message end
handle_capsule_rerun(capsule)
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 121 def handle_capsule_rerun(capsule) @test_run_count += 1 if capsule.default_usage? invoke_rspec_runner(capsule.testcase) else invoke_custom_rspec_runner(capsule.usage, capsule.testcase) end end
invoke_custom_rspec_runner(usage, testcase)
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 109 def invoke_custom_rspec_runner(usage, testcase) if @user_config.verbose $stdout << custom_usage_output = `#{usage} #{testcase.join(' ')}` else custom_usage_output = `#{usage} #{testcase.join(' ')}` end File.open(@user_config.output_file, 'a') { |f| f.puts custom_usage_output } if @user_config.output_file != File::NULL $?.exitstatus # rubocop:disable Style/SpecialGlobalVars end
invoke_rspec_runner(test)
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 97 def invoke_rspec_runner(test) configure_listener # Pass in CLI options to suppress normal output, and only run the specified test rspec_args = ['--format', 'documentation', '--out', @user_config.output_file, test] # Rspec output sent to stdout if verbose option is true rspec_args << '-fd' if @user_config.verbose return_status = RSpec::Core::Runner.run(@user_config.test_options.concat(rspec_args)) RSpec.clear_examples copy_output_to_temp_file unless @user_config.output_file == File::NULL return_status end
print_flakey_specs_detected_message()
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 130 def print_flakey_specs_detected_message puts "\n**********************************************".magenta puts ' Flakiness Detected!'.magenta puts "**********************************************\n".magenta end
print_no_flakey_specs_detected_message()
click to toggle source
# File lib/flakey_spec_catcher/runner.rb, line 136 def print_no_flakey_specs_detected_message puts "\n*************************************************".green puts ' No Flakiness Detected!'.green puts "*************************************************\n".green end