| Class | Spec::Runner::Options |
| In: |
lib/spec/runner/options.rb
|
| Parent: | Object |
| BUILT_IN_FORMATTERS | = | { 'specdoc' => Formatter::SpecdocFormatter, 's' => Formatter::SpecdocFormatter, 'html' => Formatter::HtmlFormatter, 'h' => Formatter::HtmlFormatter, 'rdoc' => Formatter::RdocFormatter, 'r' => Formatter::RdocFormatter, 'progress' => Formatter::ProgressBarFormatter, 'p' => Formatter::ProgressBarFormatter, 'failing_examples' => Formatter::FailingExamplesFormatter, 'e' => Formatter::FailingExamplesFormatter, 'failing_behaviours' => Formatter::FailingBehavioursFormatter, 'b' => Formatter::FailingBehavioursFormatter |
| backtrace_tweaker | [RW] | |
| colour | [RW] | |
| context_lines | [RW] | |
| diff_format | [RW] | |
| differ_class | [RW] | |
| dry_run | [RW] | |
| examples | [RW] | |
| failure_file | [RW] | |
| formatters | [RW] | |
| generate | [RW] | |
| heckle_runner | [RW] | |
| line_number | [RW] | |
| loadby | [RW] | |
| reporter | [RW] | |
| reverse | [RW] | |
| runner_type | [RW] | |
| timeout | [RW] | |
| verbose | [RW] |
# File lib/spec/runner/options.rb, line 40
40: def initialize
41: @backtrace_tweaker = QuietBacktraceTweaker.new
42: @examples = []
43: @formatters = []
44: @colour = false
45: @dry_run = false
46: end
# File lib/spec/runner/options.rb, line 48
48: def create_behaviour_runner
49: @formatters.each do |formatter|
50: formatter.colour = @colour if formatter.respond_to?(:colour=)
51: formatter.dry_run = @dry_run if formatter.respond_to?(:dry_run=)
52: end
53: @reporter = Reporter.new(@formatters, @backtrace_tweaker)
54:
55: # this doesn't really belong here.
56: # it should, but the way things are coupled, it doesn't
57: if @differ_class
58: Spec::Expectations.differ = @differ_class.new(@diff_format, @context_lines, @colour)
59: end
60:
61: return nil if @generate
62:
63: if @runner_type
64: @runner_type.new(self)
65: else
66: BehaviourRunner.new(self)
67: end
68: end
# File lib/spec/runner/options.rb, line 70
70: def parse_diff(format, out_stream, error_stream)
71: @context_lines = 3
72: case format
73: when :context, 'context', 'c'
74: @diff_format = :context
75: when :unified, 'unified', 'u', '', nil
76: @diff_format = :unified
77: end
78:
79: if [:context,:unified].include? @diff_format
80: require 'spec/expectations/differs/default'
81: @differ_class = Spec::Expectations::Differs::Default
82: else
83: begin
84: @diff_format = :custom
85: @differ_class = eval(format)
86: rescue NameError
87: error_stream.puts "Couldn't find differ class #{format}"
88: error_stream.puts "Make sure the --require option is specified *before* --diff"
89: exit if out_stream == $stdout
90: end
91: end
92: end
# File lib/spec/runner/options.rb, line 94
94: def parse_example(example)
95: if(File.file?(example))
96: @examples = File.open(example).read.split("\n")
97: else
98: @examples = [example]
99: end
100: end
# File lib/spec/runner/options.rb, line 102
102: def parse_format(format, out_stream, error_stream)
103: where = out_stream
104: # This funky regexp checks whether we have a FILE_NAME or not
105: if (format =~ /([a-zA-Z_]+(?:::[a-zA-Z_]+)*):?(.*)/) && ($2 != '')
106: format = $1
107: where = $2
108: else
109: raise "When using several --format options only one of them can be without a file" if @out_used
110: @out_used = true
111: end
112:
113: begin
114: formatter_type = BUILT_IN_FORMATTERS[format] || eval(format)
115: @formatters << formatter_type.new(where)
116: rescue NameError
117: error_stream.puts "Couldn't find formatter class #{format}"
118: error_stream.puts "Make sure the --require option is specified *before* --format"
119: exit if out_stream == $stdout
120: end
121: end
# File lib/spec/runner/options.rb, line 133
133: def parse_generate_options(options_file, args_copy, out_stream)
134: # Remove the --generate-options option and the argument before writing to file
135: index = args_copy.index("-G") || args_copy.index("--generate-options")
136: args_copy.delete_at(index)
137: args_copy.delete_at(index)
138:
139: File.open(options_file, 'w') do |io|
140: io.puts args_copy.join("\n")
141: end
142: out_stream.puts "\nOptions written to #{options_file}. You can now use these options with:"
143: out_stream.puts "spec --options #{options_file}"
144: @generate = true
145: end
# File lib/spec/runner/options.rb, line 127
127: def parse_heckle(heckle)
128: heckle_require = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? 'spec/runner/heckle_runner_unsupported' : 'spec/runner/heckle_runner'
129: require heckle_require
130: @heckle_runner = HeckleRunner.new(heckle)
131: end
# File lib/spec/runner/options.rb, line 123
123: def parse_require(req)
124: req.split(",").each{|file| require file}
125: end
# File lib/spec/runner/options.rb, line 147
147: def parse_runner(runner, out_stream, error_stream)
148: begin
149: @runner_type = eval(runner)
150: rescue NameError
151: error_stream.puts "Couldn't find behaviour runner class #{runner}"
152: error_stream.puts "Make sure the --require option is specified."
153: exit if out_stream == $stdout
154: end
155: end