class RspecN::Input

Attributes

command[RW]
iterations[RW]
log_path[RW]
stop_fast[RW]
write_files[RW]

Public Class Methods

new(options, args) click to toggle source
# File lib/rspec_n/input.rb, line 5
def initialize(options, args)
  @args = args
  @unprocessed_args_array = args.entries
  @options = options
  @iterations = determine_iterations
  @spec_path = determine_spec_path
  validate_order
  @order = @options.fetch(:order, "rand")
  @command = determine_command
  @stop_fast = options.fetch(:"stop-fast", false)
  @write_files = !options.fetch(:'no-file', false)
  @timestamp = options.fetch(:timestamp, false)
  @log_path = determine_log_path
end

Public Instance Methods

write_files?() click to toggle source
# File lib/rspec_n/input.rb, line 20
def write_files?
  @write_files
end

Private Instance Methods

determine_command() click to toggle source
# File lib/rspec_n/input.rb, line 48
def determine_command
  command = @options.fetch(:command, guessed_command)
  command += " #{@spec_path}" if @spec_path
  command += " --order #{@order}" if should_append_order?(command)
  command
end
determine_iterations() click to toggle source
# File lib/rspec_n/input.rb, line 33
def determine_iterations
  value = @unprocessed_args_array.detect(&:all_digits?)

  if value
    @unprocessed_args_array.delete(value)
    value.to_i
  else
    RspecN::DEFAULT_ITERATIONS
  end
end
determine_log_path() click to toggle source
# File lib/rspec_n/input.rb, line 78
def determine_log_path
  log_path = Pathname.new(@options.fetch(:dir, Dir.pwd))
  return log_path unless @timestamp

  directory_name = File.basename($PROGRAM_NAME)
  directory_name << "-#{Time.now.getlocal.strftime('%Y%m%d%H%M%S%L')}"
  log_path.join(directory_name)
end
determine_spec_path() click to toggle source
# File lib/rspec_n/input.rb, line 44
def determine_spec_path
  @unprocessed_args_array.empty? ? nil : @unprocessed_args_array.join(" ")
end
guessed_command() click to toggle source
# File lib/rspec_n/input.rb, line 55
def guessed_command
  return RspecN::DEFAULT_RSPEC_STARTER_COMMAND if project_uses_rspec_starter?
  return RspecN::DEFAULT_RAILS_COMMAND if project_is_rails_based?

  RspecN::DEFAULT_COMMAND
end
project_is_rails_based?() click to toggle source
# File lib/rspec_n/input.rb, line 67
def project_is_rails_based?
  app_file_name = "config/application.rb"
  File.file?(app_file_name) && File.readlines(app_file_name).grep(/Rails::Application/).any?
end
project_uses_rspec_starter?() click to toggle source
# File lib/rspec_n/input.rb, line 62
def project_uses_rspec_starter?
  app_file_name = "bin/start_rspec"
  File.file?(app_file_name)
end
should_append_order?(command) click to toggle source
# File lib/rspec_n/input.rb, line 72
def should_append_order?(command)
  return false if @order == "project"

  !command.include?("--order")
end
validate_order() click to toggle source
# File lib/rspec_n/input.rb, line 26
def validate_order
  order = @options.fetch(:order, nil)
  return unless order

  raise BadOption, order unless RspecN::ALLOWED_ORDER_OPTIONS.include?(order)
end