Class: FlakeySpecCatcher::RerunManager
- Inherits:
-
Object
- Object
- FlakeySpecCatcher::RerunManager
- Defined in:
- lib/flakey_spec_catcher/rerun_manager.rb
Overview
RerunManager class
Pairs file changes with user-specified re-run commands. Those pairs are defined via environment variables.
Instance Attribute Summary collapse
-
#rerun_capsules ⇒ Object
readonly
Returns the value of attribute rerun_capsules.
Instance Method Summary collapse
-
#all_non_example_groups ⇒ Object
Get all change contexts that can invoke expectations/assertions.
- #condense_reruns ⇒ Object
- #determine_rerun_usage ⇒ Object
-
#identify_tag_excluded_reruns ⇒ Object
Identifies all contexts that have a tag present.
-
#initialize(git_controller: FlakeySpecCatcher::GitController.new, user_config: FlakeySpecCatcher::UserConfig.new) ⇒ RerunManager
constructor
A new instance of RerunManager.
-
#inject_manual_reruns(patterns, usage) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- #pair_reruns_with_usages ⇒ Object
- #tests_for_rerun ⇒ Object
Constructor Details
#initialize(git_controller: FlakeySpecCatcher::GitController.new, user_config: FlakeySpecCatcher::UserConfig.new) ⇒ RerunManager
Returns a new instance of RerunManager.
13 14 15 16 17 18 19 20 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 13 def initialize(git_controller: FlakeySpecCatcher::GitController.new, user_config: FlakeySpecCatcher::UserConfig.new) @git_controller = git_controller @user_config = user_config @rerun_capsules = [] determine_rerun_usage end |
Instance Attribute Details
#rerun_capsules ⇒ Object (readonly)
Returns the value of attribute rerun_capsules.
11 12 13 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 11 def rerun_capsules @rerun_capsules end |
Instance Method Details
#all_non_example_groups ⇒ Object
Get all change contexts that can invoke expectations/assertions
49 50 51 52 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 49 def all_non_example_groups @git_controller.capsule_manager.sorted_change_contexts.reject(&:example_group?) .map(&:rerun_info) end |
#condense_reruns ⇒ Object
44 45 46 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 44 def condense_reruns @git_controller.capsule_manager.condense_reruns end |
#determine_rerun_usage ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 22 def determine_rerun_usage if @user_config.manual_rerun_patterns.nil? pair_reruns_with_usages else @rerun_capsules.clear inject_manual_reruns(@user_config.manual_rerun_patterns, @user_config.manual_rerun_usage) end end |
#identify_tag_excluded_reruns ⇒ Object
Identifies all contexts that have a tag present
55 56 57 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 55 def identify_tag_excluded_reruns @git_controller.capsule_manager.(@user_config.) end |
#inject_manual_reruns(patterns, usage) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 84 def inject_manual_reruns(patterns, usage) patterns.tr(' ', '').split(',').each do |pattern| # Check if file exists first and handle if user supplies testcase:line_number file_name = pattern.split(':')[0] line_number_present = pattern.split(':').count > 1 matching_files = Dir.glob(file_name) # If no file matches are run, don't queue up re-runs if matching_files.count.zero? puts "Specified pattern #{pattern} did not match an existing file" raise ArgumentError end # It won't make sense to have multiple files to run with one specific line number if line_number_present if matching_files.count > 1 puts "Specified pattern #{pattern} matched multiple files but a line number was given" raise ArgumentError else add_rerun_capsule(testcase: pattern, usage: usage) end # No line numbers, queue up all matching files else matching_files.each do |file| add_rerun_capsule(testcase: file, usage: usage) end end end end |
#pair_reruns_with_usages ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 59 def pair_reruns_with_usages reruns = tests_for_rerun configured_usage_patterns = @user_config.rspec_usage_patterns if configured_usage_patterns.count.zero? add_capsules_with_default_usage(reruns) return end reruns.each do |rerun| match_found = false configured_usage_patterns.each do |usage_pattern_pair| next if match_found pattern, usage = usage_pattern_pair if rerun =~ /#{pattern}/ add_rerun_capsule(testcase: rerun, usage: usage) match_found = true end end add_rerun_capsule(testcase: rerun) unless match_found end end |
#tests_for_rerun ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/flakey_spec_catcher/rerun_manager.rb', line 32 def tests_for_rerun tests = if @user_config.rerun_file_only @git_controller.capsule_manager.changed_files # If no tags are specified, condense re-runs else expand them elsif @user_config..empty? condense_reruns - identify_tag_excluded_reruns else all_non_example_groups - identify_tag_excluded_reruns end filter_reruns_by_ignore_files(tests) end |