::OptionParser
# File lib/spec/runner/option_parser.rb, line 88
88: def initialize(err, out)
89: super()
90: @error_stream = err
91: @out_stream = out
92: @options = Options.new(@error_stream, @out_stream)
93:
94: @file_factory = File
95:
96: self.banner = "Usage: spec (FILE(:LINE)?|DIRECTORY|GLOB)+ [options]"
97: self.separator ""
98: on(*OPTIONS[:pattern]) {|pattern| @options.filename_pattern = pattern}
99: on(*OPTIONS[:diff]) {|diff| @options.parse_diff(diff)}
100: on(*OPTIONS[:colour]) {@options.colour = true}
101: on(*OPTIONS[:example]) {|example| @options.parse_example(example)}
102: on(*OPTIONS[:specification]) {|example| @options.parse_example(example)}
103: on(*OPTIONS[:line]) {|line_number| @options.line_number = line_number.to_i}
104: on(*OPTIONS[:format]) {|format| @options.parse_format(format)}
105: on(*OPTIONS[:require]) {|requires| invoke_requires(requires)}
106: on(*OPTIONS[:backtrace]) {@options.backtrace_tweaker = NoisyBacktraceTweaker.new}
107: on(*OPTIONS[:loadby]) {|loadby| @options.loadby = loadby}
108: on(*OPTIONS[:reverse]) {@options.reverse = true}
109: on(*OPTIONS[:timeout]) {|timeout| @options.timeout = timeout.to_f}
110: on(*OPTIONS[:heckle]) {|heckle| @options.load_heckle_runner(heckle)}
111: on(*OPTIONS[:dry_run]) {@options.dry_run = true}
112: on(*OPTIONS[:options_file]) {|options_file|}
113: on(*OPTIONS[:generate_options]) {|options_file|}
114: on(*OPTIONS[:runner]) {|runner| @options.user_input_for_runner = runner}
115: on(*OPTIONS[:debug]) {@options.debug = true}
116: on(*OPTIONS[:drb]) {}
117: on(*OPTIONS[:drb_port]) {|port| @options.drb_port = port}
118: on(*OPTIONS[:version]) {parse_version}
119: on("--autospec") {@options.autospec = true}
120: on_tail(*OPTIONS[:help]) {parse_help}
121: end
# File lib/spec/runner/option_parser.rb, line 123
123: def order!(argv, &blk)
124: @argv = argv.dup
125: @argv = (@argv.empty? & self.class.spec_command?) ? ['--help'] : @argv
126:
127: # Parse options file first
128: parse_file_options(:options_file, :parse_options_file)
129:
130: @options.argv = @argv.dup
131: return if parse_file_options(:generate_options, :write_options_file)
132: return if parse_drb
133:
134: super(@argv) do |file|
135: if file =~ /^(.+):(\d+)$/
136: file = $1
137: @options.line_number = $2.to_i
138: end
139:
140: @options.files << file
141: blk.call(file) if blk
142: end
143:
144: @options
145: end
# File lib/spec/runner/option_parser.rb, line 149
149: def invoke_requires(requires)
150: requires.split(",").each do |file|
151: require file
152: end
153: end
# File lib/spec/runner/option_parser.rb, line 195
195: def parse_drb
196: argv = @options.argv
197: is_drb = false
198: is_drb ||= argv.delete(OPTIONS[:drb][0])
199: is_drb ||= argv.delete(OPTIONS[:drb][1])
200: return false unless is_drb
201: if DrbCommandLine.run(self.class.parse(argv, @error_stream, @out_stream))
202: @options.examples_should_not_be_run
203: true
204: else
205: @error_stream.puts "Running specs locally:"
206: false
207: end
208: end
# File lib/spec/runner/option_parser.rb, line 155
155: def parse_file_options(option_name, action)
156: # Remove the file option and the argument before handling the file
157: options_file = nil
158: options_list = OPTIONS[option_name][0..1]
159: options_list[1].gsub!(" PATH", "")
160: options_list.each do |option|
161: if index = @argv.index(option)
162: @argv.delete_at(index)
163: options_file = @argv.delete_at(index)
164: end
165: end
166:
167: if options_file.nil? &&
168: File.exist?('spec/spec.opts') &&
169: !@argv.any?{|a| a =~ /^\-/ }
170: options_file = 'spec/spec.opts'
171: end
172:
173: if options_file
174: send(action, options_file)
175: return true
176: else
177: return false
178: end
179: end
# File lib/spec/runner/option_parser.rb, line 215
215: def parse_help
216: @out_stream.puts self
217: exit if stdout?
218: end
# File lib/spec/runner/option_parser.rb, line 181
181: def parse_options_file(options_file)
182: option_file_args = File.readlines(options_file).map {|l| l.chomp.split " "}.flatten
183: @argv.push(*option_file_args)
184: end
# File lib/spec/runner/option_parser.rb, line 210
210: def parse_version
211: @out_stream.puts ::Spec::VERSION::SUMMARY
212: exit if stdout?
213: end
# File lib/spec/runner/option_parser.rb, line 220
220: def stdout?
221: @out_stream == $stdout
222: end
# File lib/spec/runner/option_parser.rb, line 186
186: def write_options_file(options_file)
187: File.open(options_file, 'w') do |io|
188: io.puts @argv.join("\n")
189: end
190: @out_stream.puts "\nOptions written to #{options_file}. You can now use these options with:"
191: @out_stream.puts "spec --options #{options_file}"
192: @options.examples_should_not_be_run
193: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.