16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/spec/runner/option_parser.rb', line 16
def self.parse(args, standalone, err, out)
options = OpenStruct.new
options.out = out
options.formatter_type = Formatter::ProgressBarFormatter
options.backtrace_tweaker = QuietBacktraceTweaker.new
options.spec_name = nil
opts = ::OptionParser.new do |opts|
opts.banner = "Usage: spec [options] (FILE|DIRECTORY|GLOB)+"
opts.separator ""
opts.on("--diff", "Show unified diff of Strings that are expected to be equal when they are not") do
require 'spec/api/helper/diff'
end
opts.on("-s", "--spec SPECIFICATION_NAME", "Execute a single specification") do |spec_name|
options.spec_name = spec_name
end
opts.on("-f", "--format FORMAT", "Builtin formats: specdoc|s|rdoc|r|html|h",
"You can also specify a custom formatter class",
"(in which case you should also specify --require)") do |format|
case format
when 'specdoc', 's'
options.formatter_type = Formatter::SpecdocFormatter
when 'html', 'h'
options.formatter_type = Formatter::HtmlFormatter
when 'rdoc', 'r'
options.formatter_type = Formatter::RdocFormatter
options.dry_run = true
else
begin
options.formatter_type = eval(format)
rescue NameError
err.puts "Couldn't find formatter class #{format}"
err.puts "Make sure the --require option is specified *before* --format"
exit if out == $stdout
end
end
end
opts.on("-r", "--require FILE", "Require FILE before running specs",
"Useful for loading custom formatters or other extensions") do |req|
require req
end
opts.on("-b", "--backtrace", "Output full backtrace") do
options.backtrace_tweaker = NoisyBacktraceTweaker.new
end
opts.on("-d", "--dry-run", "Don't execute specs") do
options.dry_run = true
end
opts.on("-v", "--version", "Show version") do
out.puts ::Spec::VERSION::DESCRIPTION
exit if out == $stdout
end
opts.on_tail("-h", "--help", "You're looking at it") do
out.puts opts
exit if out == $stdout
end
end
opts.parse!(args)
if args.empty?
err.puts opts unless standalone
exit if err == $stderr unless standalone
end
options
end
|