Module: SpecSelectorUtil::State
- Included in:
- SpecSelector
- Defined in:
- lib/spec_selector/state.rb
Overview
The State module contains methods that facilitate example rerun and filtering
Instance Method Summary collapse
- #add_or_remove_from_filter ⇒ Object
- #appended_arguments ⇒ Object
- #check_inclusion_status(item) ⇒ Object
- #clear_filter ⇒ Object
- #delete_filter_data ⇒ Object
- #display_rerun ⇒ Object
- #filter_include(item = @selected) ⇒ Object
- #filter_remove ⇒ Object
- #persist_descriptions ⇒ Object
- #persist_filter ⇒ Object
- #persist_locations ⇒ Object
- #prepare_description_arguments ⇒ Object
- #prepare_location_arguments ⇒ Object
- #prepare_rerun ⇒ Object
- #remove_old_descriptions ⇒ Object
- #remove_old_locations ⇒ Object
- #rerun ⇒ Object
- #rerun_all ⇒ Object
- #reset_arguments ⇒ Object
- #run_only_fails ⇒ Object
- #top_fail! ⇒ Object
Instance Method Details
#add_or_remove_from_filter ⇒ Object
70 71 72 73 74 75 |
# File 'lib/spec_selector/state.rb', line 70 def add_or_remove_from_filter return if @instructions @selected.[:include] ? filter_remove : filter_include refresh_display end |
#appended_arguments ⇒ Object
40 41 42 43 44 |
# File 'lib/spec_selector/state.rb', line 40 def appended_arguments return [nil, 0] if location_mode? [prepare_description_arguments, @filtered_descriptions.count] end |
#check_inclusion_status(item) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/spec_selector/state.rb', line 152 def check_inclusion_status(item) return unless @last_run_descriptions.include?(item.[:full_description]) @inclusion_filter << item item.[:include] = true end |
#clear_filter ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/spec_selector/state.rb', line 134 def clear_filter return if @inclusion_filter.empty? @inclusion_filter.each { |item| item.[:include] = nil } @inclusion_filter = [] return if @instructions @example_display ? display_example : top_level_list end |
#delete_filter_data ⇒ Object
86 87 88 89 90 |
# File 'lib/spec_selector/state.rb', line 86 def delete_filter_data [@descriptions_file, @locations_file].each do |file| File.delete(file) if File.exist?(file) end end |
#display_rerun ⇒ Object
34 35 36 37 38 |
# File 'lib/spec_selector/state.rb', line 34 def display_rerun close_alt_buffer if @instructions clear_frame italicize('running examples...') end |
#filter_include(item = @selected) ⇒ Object
20 21 22 23 24 |
# File 'lib/spec_selector/state.rb', line 20 def filter_include(item = @selected) @filter_mode = :location if one_liner?(item) item.[:include] = true @inclusion_filter << item end |
#filter_remove ⇒ Object
64 65 66 67 68 |
# File 'lib/spec_selector/state.rb', line 64 def filter_remove @inclusion_filter -= [@selected] @selected.[:include] = nil @filter_mode = :descripton unless @inclusion_filter.any? { |item| one_liner?(item) } end |
#persist_descriptions ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/spec_selector/state.rb', line 77 def persist_descriptions @filtered_descriptions = @inclusion_filter.map do |item| item.[:full_description] end filter = @filtered_descriptions.to_json File.write(@descriptions_file, filter) end |
#persist_filter ⇒ Object
46 47 48 49 |
# File 'lib/spec_selector/state.rb', line 46 def persist_filter persist_descriptions persist_locations if location_mode? end |
#persist_locations ⇒ Object
109 110 111 112 113 |
# File 'lib/spec_selector/state.rb', line 109 def persist_locations @filtered_locations = @inclusion_filter.map(&:location) locations = @filtered_locations.to_json File.write(@locations_file, locations) end |
#prepare_description_arguments ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/spec_selector/state.rb', line 119 def prepare_description_arguments return if @inclusion_filter.empty? contains_singles = @filtered_descriptions.select { |desc| desc.include?("'") } included = @filtered_descriptions - contains_singles return contains_singles.to_s if included.empty? included = included.to_s.gsub('"', "'") return included if contains_singles.empty? contains_singles.map!(&:dump) included[-1] = ", #{contains_singles.join(', ')}]" included end |
#prepare_location_arguments ⇒ Object
115 116 117 |
# File 'lib/spec_selector/state.rb', line 115 def prepare_location_arguments @rerun_arguments += " #{@filtered_locations.join(' ')}" end |
#prepare_rerun ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/spec_selector/state.rb', line 26 def prepare_rerun display_rerun persist_filter reset_arguments prepare_location_arguments if location_mode? delete_filter_data if @inclusion_filter.empty? end |
#remove_old_descriptions ⇒ Object
103 104 105 106 107 |
# File 'lib/spec_selector/state.rb', line 103 def remove_old_descriptions old_descriptions = @last_run_descriptions.map { |desc| "-e #{desc}" } @rerun_arguments = ARGV.join(' ') old_descriptions.each { |desc| @rerun_arguments.slice!(desc) } end |
#remove_old_locations ⇒ Object
97 98 99 100 101 |
# File 'lib/spec_selector/state.rb', line 97 def remove_old_locations return if @last_run_locations.empty? @last_run_locations.each { |loc| @rerun_arguments.slice!(loc) } end |
#rerun ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/spec_selector/state.rb', line 6 def rerun prepare_rerun descriptions, marker = appended_arguments rerun_script = "#{current_path}/scripts/rerun.sh" prepended = [rerun_script, Process.pid, Dir.pwd].join(' ') Signal.trap('TERM') do clear_frame exit end system("#{prepended} #{$PROGRAM_NAME} #{@rerun_arguments} #{descriptions} #{marker}") end |
#rerun_all ⇒ Object
59 60 61 62 |
# File 'lib/spec_selector/state.rb', line 59 def rerun_all @inclusion_filter = [] rerun end |
#reset_arguments ⇒ Object
92 93 94 95 |
# File 'lib/spec_selector/state.rb', line 92 def reset_arguments remove_old_descriptions remove_old_locations end |
#run_only_fails ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/spec_selector/state.rb', line 51 def run_only_fails return if @failed.empty? @inclusion_filter = [] @failed.each { |example| filter_include(example) } rerun end |
#top_fail! ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/spec_selector/state.rb', line 144 def top_fail! return if @failed.empty? @inclusion_filter = [] filter_include(@failed.first) rerun end |