module SpecSelectorUtil::State

Public Instance Methods

appended_arguments() click to toggle source
# File lib/spec_selector/state.rb, line 32
def appended_arguments
  return [nil, 0] if location_mode?

  [prepare_description_arguments, @filtered_descriptions.count]
end
check_inclusion_status(item) click to toggle source
# File lib/spec_selector/state.rb, line 136
def check_inclusion_status(item)
  if @last_run_descriptions.include?(item.metadata[:full_description])
    @inclusion_filter << item
    item.metadata[:include] = true
  end
end
clear_filter() click to toggle source
# File lib/spec_selector/state.rb, line 119
def clear_filter
  return if @inclusion_filter.empty?

  @inclusion_filter.each { |item| item.metadata[:include] = nil }
  @inclusion_filter = []
  return if @instructions

  @example_display ? display_example : top_level_list
end
delete_filter_data() click to toggle source
# File lib/spec_selector/state.rb, line 71
def delete_filter_data
  [@descriptions_file, @locations_file].each do |file|
    File.delete(file) if File.exist?(file)
  end
end
display_rerun() click to toggle source
# File lib/spec_selector/state.rb, line 26
def display_rerun
  close_alt_buffer if @instructions
  clear_frame
  italicize('running examples...')
end
filter_include(item = @selected) click to toggle source
# File lib/spec_selector/state.rb, line 12
def filter_include(item = @selected)
  @filter_mode = :location if one_liner?(item)
  item.metadata[:include] = true
  @inclusion_filter << item
end
filter_remove() click to toggle source
# File lib/spec_selector/state.rb, line 56
def filter_remove
  @inclusion_filter -= [@selected]
  @selected.metadata[:include] = nil
  @filter_mode = :descripton unless @inclusion_filter.any? { |item| one_liner?(item) }
end
persist_descriptions() click to toggle source
# File lib/spec_selector/state.rb, line 62
def persist_descriptions
  @filtered_descriptions = @inclusion_filter.map do |item|
    item.metadata[:full_description]
  end

  filter = @filtered_descriptions.to_json
  File.write(@descriptions_file, filter)
end
persist_filter() click to toggle source
# File lib/spec_selector/state.rb, line 38
def persist_filter
  persist_descriptions
  persist_locations if location_mode?
end
persist_locations() click to toggle source
# File lib/spec_selector/state.rb, line 94
def persist_locations
  @filtered_locations = @inclusion_filter.map { |item| item.location }
  locations = @filtered_locations.to_json
  File.write(@locations_file, locations)
end
prepare_description_arguments() click to toggle source
# File lib/spec_selector/state.rb, line 104
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() click to toggle source
# File lib/spec_selector/state.rb, line 100
def prepare_location_arguments
  @rerun_arguments += " #{@filtered_locations.join(' ')}"
end
prepare_rerun() click to toggle source
# File lib/spec_selector/state.rb, line 18
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() click to toggle source
# File lib/spec_selector/state.rb, line 88
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() click to toggle source
# File lib/spec_selector/state.rb, line 82
def remove_old_locations
  return if @last_run_locations.empty?

  @last_run_locations.each { |loc| @rerun_arguments.slice!(loc) }
end
rerun() click to toggle source
# File lib/spec_selector/state.rb, line 3
def rerun
  prepare_rerun
  descriptions, marker = appended_arguments
  rerun_script = current_path + '/scripts/rerun.sh'
  prepend = [rerun_script, Process.pid, Dir.pwd].join(' ')
  Signal.trap('TERM') { clear_frame; exit }
  system("#{prepend} #{$0} #{@rerun_arguments} #{descriptions} #{marker}")
end
rerun_all() click to toggle source
# File lib/spec_selector/state.rb, line 51
def rerun_all
  @inclusion_filter = []
  rerun
end
reset_arguments() click to toggle source
# File lib/spec_selector/state.rb, line 77
def reset_arguments
  remove_old_descriptions
  remove_old_locations
end
run_only_fails() click to toggle source
# File lib/spec_selector/state.rb, line 43
def run_only_fails
  return if @failed.empty?

  @inclusion_filter = []
  @failed.each { |example| filter_include(example) }
  rerun
end
top_fail!() click to toggle source
# File lib/spec_selector/state.rb, line 129
def top_fail!
  return if @failed.empty?
  @inclusion_filter = []
  filter_include(@failed.first)
  rerun
end