Class: ArgumentsHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_n/helpers/arguments_helper.rb

Class Method Summary collapse

Class Method Details

.argumentsObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/rspec_n/helpers/arguments_helper.rb', line 5

def arguments
  if File.exist?(".rspec_n") && no_options_in_arguments?
    options = read_options_from_file
    if options.any?
      print "Reading options from `.rspec_n` file\n"
      return ARGV + options
    end
  end
  ARGV
end

.no_options_in_arguments?Boolean

Read arguments from the config file only if no arguments are provided by user

Returns:

  • (Boolean)


17
18
19
# File 'lib/rspec_n/helpers/arguments_helper.rb', line 17

def no_options_in_arguments?
  ARGV.grep(/^-/).empty? # Match args that start with - (or --). Those are the options.
end

.read_options_from_fileObject

Options can be listed on a single line in the config file, or listed on separate lines.



22
23
24
# File 'lib/rspec_n/helpers/arguments_helper.rb', line 22

def read_options_from_file
  Shellwords.shellwords File.read(".rspec_n").to_s.gsub(/\n|\r\n/, " ")
end