Class | Spec::Runner::OptionParser |
In: |
vendor/plugins/rspec/lib/spec/runner/option_parser.rb
|
Parent: | ::OptionParser |
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 85 85: def initialize(err, out) 86: super() 87: @error_stream = err 88: @out_stream = out 89: @options = Options.new(@error_stream, @out_stream) 90: 91: @file_factory = File 92: 93: self.banner = "Usage: spec (FILE|DIRECTORY|GLOB)+ [options]" 94: self.separator "" 95: on(*OPTIONS[:pattern]) {|pattern| @options.filename_pattern = pattern} 96: on(*OPTIONS[:diff]) {|diff| @options.parse_diff(diff)} 97: on(*OPTIONS[:colour]) {@options.colour = true} 98: on(*OPTIONS[:example]) {|example| @options.parse_example(example)} 99: on(*OPTIONS[:specification]) {|example| @options.parse_example(example)} 100: on(*OPTIONS[:line]) {|line_number| @options.line_number = line_number.to_i} 101: on(*OPTIONS[:format]) {|format| @options.parse_format(format)} 102: on(*OPTIONS[:require]) {|requires| invoke_requires(requires)} 103: on(*OPTIONS[:backtrace]) {@options.backtrace_tweaker = NoisyBacktraceTweaker.new} 104: on(*OPTIONS[:loadby]) {|loadby| @options.loadby = loadby} 105: on(*OPTIONS[:reverse]) {@options.reverse = true} 106: on(*OPTIONS[:timeout]) {|timeout| @options.timeout = timeout.to_f} 107: on(*OPTIONS[:heckle]) {|heckle| @options.load_heckle_runner(heckle)} 108: on(*OPTIONS[:dry_run]) {@options.dry_run = true} 109: on(*OPTIONS[:options_file]) {|options_file| parse_options_file(options_file)} 110: on(*OPTIONS[:generate_options]) do |options_file| 111: end 112: on(*OPTIONS[:runner]) do |runner| 113: @options.user_input_for_runner = runner 114: end 115: on(*OPTIONS[:drb]) {} 116: on(*OPTIONS[:version]) {parse_version} 117: on_tail(*OPTIONS[:help]) {parse_help} 118: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 8 8: def parse(args, err, out) 9: parser = new(err, out) 10: parser.parse(args) 11: parser.options 12: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 120 120: def order!(argv, &blk) 121: @argv = argv 122: @options.argv = @argv.dup 123: return if parse_generate_options 124: return if parse_drb 125: 126: super(@argv) do |file| 127: @options.files << file 128: blk.call(file) if blk 129: end 130: 131: @options 132: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 135 135: def invoke_requires(requires) 136: requires.split(",").each do |file| 137: require file 138: end 139: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 173 173: def parse_drb 174: is_drb = false 175: argv = @options.argv 176: is_drb ||= argv.delete(OPTIONS[:drb][0]) 177: is_drb ||= argv.delete(OPTIONS[:drb][1]) 178: return nil unless is_drb 179: @options.examples_should_not_be_run 180: DrbCommandLine.run( 181: self.class.parse(argv, @error_stream, @out_stream) 182: ) 183: true 184: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 146 146: def parse_generate_options 147: # Remove the --generate-options option and the argument before writing to file 148: options_file = nil 149: ['-G', '--generate-options'].each do |option| 150: if index = @argv.index(option) 151: @argv.delete_at(index) 152: options_file = @argv.delete_at(index) 153: end 154: end 155: 156: if options_file 157: write_generated_options(options_file) 158: return true 159: else 160: return false 161: end 162: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 191 191: def parse_help 192: @out_stream.puts self 193: exit if stdout? 194: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 141 141: def parse_options_file(options_file) 142: option_file_args = IO.readlines(options_file).map {|l| l.chomp.split " "}.flatten 143: @argv.push(*option_file_args) 144: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 186 186: def parse_version 187: @out_stream.puts ::Spec::VERSION::DESCRIPTION 188: exit if stdout? 189: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 196 196: def stdout? 197: @out_stream == $stdout 198: end
# File vendor/plugins/rspec/lib/spec/runner/option_parser.rb, line 164 164: def write_generated_options(options_file) 165: File.open(options_file, 'w') do |io| 166: io.puts @argv.join("\n") 167: end 168: @out_stream.puts "\nOptions written to #{options_file}. You can now use these options with:" 169: @out_stream.puts "spec --options #{options_file}" 170: @options.examples_should_not_be_run 171: end