Parent

Class/Module Index [+]

Quicksearch

Spec::Runner::OptionParser

Constants

OPTIONS

Attributes

options[R]

Public Class Methods

new(err, out) click to toggle source
# File lib/spec/runner/option_parser.rb, line 88
def initialize(err, out)
  super()
  @error_stream = err
  @out_stream = out
  @options = Options.new(@error_stream, @out_stream)

  @file_factory = File

  self.banner = "Usage: spec (FILE(:LINE)?|DIRECTORY|GLOB)+ [options]"
  self.separator ""
  on(*OPTIONS[:pattern])          {|pattern| @options.filename_pattern = pattern}
  on(*OPTIONS[:diff])             {|diff| @options.parse_diff(diff)}
  on(*OPTIONS[:colour])           {@options.colour = true}
  on(*OPTIONS[:example])          {|example| @options.parse_example(example)}
  on(*OPTIONS[:specification])    {|example| @options.parse_example(example)}
  on(*OPTIONS[:line])             {|line_number| @options.line_number = line_number.to_i}
  on(*OPTIONS[:format])           {|format| @options.parse_format(format)}
  on(*OPTIONS[:require])          {|requires| invoke_requires(requires)}
  on(*OPTIONS[:backtrace])        {@options.backtrace_tweaker = NoisyBacktraceTweaker.new}
  on(*OPTIONS[:loadby])           {|loadby| @options.loadby = loadby}
  on(*OPTIONS[:reverse])          {@options.reverse = true}
  on(*OPTIONS[:timeout])          {|timeout| @options.timeout = timeout.to_f}
  on(*OPTIONS[:heckle])           {|heckle| @options.load_heckle_runner(heckle)}
  on(*OPTIONS[:dry_run])          {@options.dry_run = true}
  on(*OPTIONS[:options_file])     {|options_file|}
  on(*OPTIONS[:generate_options]) {|options_file|}
  on(*OPTIONS[:runner])           {|runner|  @options.user_input_for_runner = runner}
  on(*OPTIONS[:debug])            {@options.debug = true}
  on(*OPTIONS[:drb])              {}
  on(*OPTIONS[:drb_port])         {|port| @options.drb_port = port}
  on(*OPTIONS[:version])          {parse_version}
  on("--autospec")                {@options.autospec = true}
  on_tail(*OPTIONS[:help])        {parse_help}
end
parse(args, err, out) click to toggle source
# File lib/spec/runner/option_parser.rb, line 8
def parse(args, err, out)
  parser = new(err, out)
  parser.parse(args)
  parser.options
end
spec_command?() click to toggle source
# File lib/spec/runner/option_parser.rb, line 14
def spec_command?
  $0.split('/').last == 'spec'
end

Public Instance Methods

order!(argv, &blk) click to toggle source
# File lib/spec/runner/option_parser.rb, line 123
def order!(argv, &blk)
  @argv = argv.dup
  @argv = (@argv.empty? & self.class.spec_command?) ? ['--help'] : @argv

  # Parse options file first
  parse_file_options(:options_file, :parse_options_file)

  @options.argv = @argv.dup
  return if parse_file_options(:generate_options, :write_options_file)
  return if parse_drb

  super(@argv) do |file|
    if file =~ /^(.+):(\d+)$/
      file = $1
      @options.line_number = $2.to_i
    end

    @options.files << file
    blk.call(file) if blk
  end

  @options
end

Protected Instance Methods

invoke_requires(requires) click to toggle source
# File lib/spec/runner/option_parser.rb, line 149
def invoke_requires(requires)
  requires.split(",").each do |file|
    require file
  end
end
parse_drb() click to toggle source
# File lib/spec/runner/option_parser.rb, line 195
def parse_drb
  argv = @options.argv
  is_drb = false
  is_drb ||= argv.delete(OPTIONS[:drb][0])
  is_drb ||= argv.delete(OPTIONS[:drb][1])
  return false unless is_drb
  if DrbCommandLine.run(self.class.parse(argv, @error_stream, @out_stream))
    @options.examples_should_not_be_run
    true
  else
    @error_stream.puts "Running specs locally:"
    false
  end
end
parse_file_options(option_name, action) click to toggle source
# File lib/spec/runner/option_parser.rb, line 155
def parse_file_options(option_name, action)
  # Remove the file option and the argument before handling the file
  options_file = nil
  options_list = OPTIONS[option_name][0..1]
  options_list[1].gsub!(" PATH", "")
  options_list.each do |option|
    if index = @argv.index(option)
      @argv.delete_at(index)
      options_file = @argv.delete_at(index)
    end
  end
  
  if options_file.nil? &&
     File.exist?('spec/spec.opts') &&
     !@argv.any?{|a| a =~ /^\-/ }
       options_file = 'spec/spec.opts'
  end

  if options_file
    send(action, options_file)
    return true
  else
    return false
  end
end
parse_help() click to toggle source
# File lib/spec/runner/option_parser.rb, line 215
def parse_help
  @out_stream.puts self
  exit if stdout?
end
parse_options_file(options_file) click to toggle source
# File lib/spec/runner/option_parser.rb, line 181
def parse_options_file(options_file)
  option_file_args = File.readlines(options_file).map {|l| l.chomp.split " "}.flatten
  @argv.push(*option_file_args)
end
parse_version() click to toggle source
# File lib/spec/runner/option_parser.rb, line 210
def parse_version
  @out_stream.puts ::Spec::VERSION::SUMMARY
  exit if stdout?
end
stdout?() click to toggle source
# File lib/spec/runner/option_parser.rb, line 220
def stdout?
  @out_stream == $stdout
end
write_options_file(options_file) click to toggle source
# File lib/spec/runner/option_parser.rb, line 186
def write_options_file(options_file)
  File.open(options_file, 'w') do |io|
    io.puts @argv.join("\n")
  end
  @out_stream.puts "\nOptions written to #{options_file}. You can now use these options with:"
  @out_stream.puts "spec --options #{options_file}"
  @options.examples_should_not_be_run
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.