Methods
Constants
FILE_SORTERS = { 'mtime' => lambda {|file_a, file_b| File.mtime(file_b) <=> File.mtime(file_a)}
EXAMPLE_FORMATTERS = { # Load these lazily for better speed 'specdoc' => ['spec/runner/formatter/specdoc_formatter', 'Formatter::SpecdocFormatter'], 's' => ['spec/runner/formatter/specdoc_formatter', 'Formatter::SpecdocFormatter'], 'html' => ['spec/runner/formatter/html_formatter', 'Formatter::HtmlFormatter'], 'h' => ['spec/runner/formatter/html_formatter', 'Formatter::HtmlFormatter'], 'progress' => ['spec/runner/formatter/progress_bar_formatter', 'Formatter::ProgressBarFormatter'], 'p' => ['spec/runner/formatter/progress_bar_formatter', 'Formatter::ProgressBarFormatter'], 'failing_examples' => ['spec/runner/formatter/failing_examples_formatter', 'Formatter::FailingExamplesFormatter'], 'e' => ['spec/runner/formatter/failing_examples_formatter', 'Formatter::FailingExamplesFormatter'], 'failing_example_groups' => ['spec/runner/formatter/failing_example_groups_formatter', 'Formatter::FailingExampleGroupsFormatter'], 'g' => ['spec/runner/formatter/failing_example_groups_formatter', 'Formatter::FailingExampleGroupsFormatter'], 'profile' => ['spec/runner/formatter/profile_formatter', 'Formatter::ProfileFormatter'], 'o' => ['spec/runner/formatter/profile_formatter', 'Formatter::ProfileFormatter'], 'textmate' => ['spec/runner/formatter/text_mate_formatter', 'Formatter::TextMateFormatter']
STORY_FORMATTERS = { 'plain' => ['spec/runner/formatter/story/plain_text_formatter', 'Formatter::Story::PlainTextFormatter'], 'p' => ['spec/runner/formatter/story/plain_text_formatter', 'Formatter::Story::PlainTextFormatter'], 'html' => ['spec/runner/formatter/story/html_formatter', 'Formatter::Story::HtmlFormatter'], 'h' => ['spec/runner/formatter/story/html_formatter', 'Formatter::Story::HtmlFormatter']
Attributes
[RW] argv
[RW] backtrace_tweaker
[R] colour
[RW] context_lines
[RW] diff_format
[R] differ_class
[RW] dry_run
[RW] error_stream
[R] example_groups
[RW] examples
[RW] filename_pattern
[R] files
[RW] heckle_runner
[RW] line_number
[RW] loadby
[RW] output_stream
[RW] profile
[RW] reporter
[RW] reverse
[RW] timeout
[RW] user_input_for_runner
[RW] verbose
Public Class methods
new(error_stream, output_stream)
    # File lib/spec/runner/options.rb, line 54
54:       def initialize(error_stream, output_stream)
55:         @error_stream = error_stream
56:         @output_stream = output_stream
57:         @filename_pattern = "**/*_spec.rb"
58:         @backtrace_tweaker = QuietBacktraceTweaker.new
59:         @examples = []
60:         @colour = false
61:         @profile = false
62:         @dry_run = false
63:         @reporter = Reporter.new(self)
64:         @context_lines = 3
65:         @diff_format  = :unified
66:         @files = []
67:         @example_groups = []
68:         @examples_run = false
69:         @examples_should_be_run = nil
70:         @user_input_for_runner = nil
71:       end
Public Instance methods
add_example_group(example_group)
    # File lib/spec/runner/options.rb, line 73
73:       def add_example_group(example_group)
74:         @example_groups << example_group
75:       end
colour=(colour)
     # File lib/spec/runner/options.rb, line 105
105:       def colour=(colour)
106:         @colour = colour
107:         if @colour && RUBY_PLATFORM =~ /win32/ ;\
108:           begin ;\
109:             require 'rubygems' ;\
110:             require 'Win32/Console/ANSI' ;\
111:           rescue LoadError ;\
112:             warn "You must 'gem install win32console' to use colour on Windows" ;\
113:             @colour = false ;\
114:           end
115:         end
116:       end
examples_run?()
    # File lib/spec/runner/options.rb, line 97
97:       def examples_run?
98:         @examples_run
99:       end
examples_should_not_be_run()
     # File lib/spec/runner/options.rb, line 101
101:       def examples_should_not_be_run
102:         @examples_should_be_run = false
103:       end
files_to_load()
     # File lib/spec/runner/options.rb, line 187
187:       def files_to_load
188:         result = []
189:         sorted_files.each do |file|
190:           if File.directory?(file)
191:             filename_pattern.split(",").each do |pattern|
192:               result += Dir[File.expand_path("#{file}/#{pattern.strip}")]
193:             end
194:           elsif File.file?(file)
195:             result << file
196:           else
197:             raise "File or directory not found: #{file}"
198:           end
199:         end
200:         result
201:       end
formatters()
     # File lib/spec/runner/options.rb, line 151
151:       def formatters
152:         @format_options ||= [['progress', @output_stream]]
153:         @formatters ||= load_formatters(@format_options, EXAMPLE_FORMATTERS)
154:       end
load_formatters(format_options, formatters)
     # File lib/spec/runner/options.rb, line 161
161:       def load_formatters(format_options, formatters)
162:         format_options.map do |format, where|
163:           formatter_type = if formatters[format]
164:             require formatters[format][0]
165:             eval(formatters[format][1], binding, __FILE__, __LINE__)
166:           else
167:             load_class(format, 'formatter', '--format')
168:           end
169:           formatter_type.new(self, where)
170:         end
171:       end
load_heckle_runner(heckle)
     # File lib/spec/runner/options.rb, line 173
173:       def load_heckle_runner(heckle)
174:         suffix = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? '_unsupported' : ''
175:         require "spec/runner/heckle_runner#{suffix}"
176:         @heckle_runner = HeckleRunner.new(heckle)
177:       end
number_of_examples()
     # File lib/spec/runner/options.rb, line 179
179:       def number_of_examples
180:         total = 0
181:         @example_groups.each do |example_group|
182:           total += example_group.number_of_examples
183:         end
184:         total
185:       end
parse_diff(format)
     # File lib/spec/runner/options.rb, line 118
118:       def parse_diff(format)
119:         case format
120:         when :context, 'context', 'c'
121:           @diff_format  = :context
122:           default_differ
123:         when :unified, 'unified', 'u', '', nil
124:           @diff_format  = :unified
125:           default_differ
126:         else
127:           @diff_format  = :custom
128:           self.differ_class = load_class(format, 'differ', '--diff')
129:         end
130:       end
parse_example(example)
     # File lib/spec/runner/options.rb, line 132
132:       def parse_example(example)
133:         if(File.file?(example))
134:           @examples = File.open(example).read.split("\n")
135:         else
136:           @examples = [example]
137:         end
138:       end
parse_format(format_arg)
     # File lib/spec/runner/options.rb, line 140
140:       def parse_format(format_arg)
141:         format, where = ClassAndArgumentsParser.parse(format_arg)
142:         unless where
143:           raise "When using several --format options only one of them can be without a file" if @out_used
144:           where = @output_stream
145:           @out_used = true
146:         end
147:         @format_options ||= []
148:         @format_options << [format, where]
149:       end
remove_example_group(example_group)
    # File lib/spec/runner/options.rb, line 77
77:       def remove_example_group(example_group)
78:         @example_groups.delete(example_group)
79:       end
run_examples()
    # File lib/spec/runner/options.rb, line 81
81:       def run_examples
82:         return true unless examples_should_be_run?
83:         runner = custom_runner || ExampleGroupRunner.new(self)
84: 
85:         runner.load_files(files_to_load)
86:         if example_groups.empty?
87:           true
88:         else
89:           set_spec_from_line_number if line_number
90:           success = runner.run
91:           @examples_run = true
92:           heckle if heckle_runner
93:           success
94:         end
95:       end
story_formatters()
     # File lib/spec/runner/options.rb, line 156
156:       def story_formatters
157:         @format_options ||= [['plain', @output_stream]]
158:         @formatters ||= load_formatters(@format_options, STORY_FORMATTERS)
159:       end
Protected Instance methods
custom_runner()
     # File lib/spec/runner/options.rb, line 233
233:       def custom_runner
234:         return nil unless custom_runner?
235:         klass_name, arg = ClassAndArgumentsParser.parse(user_input_for_runner)
236:         runner_type = load_class(klass_name, 'behaviour runner', '--runner')
237:         return runner_type.new(self, arg)
238:       end
custom_runner?()
     # File lib/spec/runner/options.rb, line 240
240:       def custom_runner?
241:         return user_input_for_runner ? true : false
242:       end
default_differ()
     # File lib/spec/runner/options.rb, line 258
258:       def default_differ
259:         require 'spec/expectations/differs/default'
260:         self.differ_class = Spec::Expectations::Differs::Default
261:       end
differ_class=(klass)
     # File lib/spec/runner/options.rb, line 209
209:       def differ_class=(klass)
210:         return unless klass
211:         @differ_class = klass
212:         Spec::Expectations.differ = self.differ_class.new(self)
213:       end
examples_should_be_run?()
     # File lib/spec/runner/options.rb, line 204
204:       def examples_should_be_run?
205:         return @examples_should_be_run unless @examples_should_be_run.nil?
206:         @examples_should_be_run = true
207:       end
heckle()
     # File lib/spec/runner/options.rb, line 244
244:       def heckle
245:         returns = self.heckle_runner.heckle_with
246:         self.heckle_runner = nil
247:         returns
248:       end
load_class(name, kind, option)
     # File lib/spec/runner/options.rb, line 215
215:       def load_class(name, kind, option)
216:         if name =~ /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/
217:           arg = $2 == "" ? nil : $2
218:           [$1, arg]
219:         else
220:           m = "#{name.inspect} is not a valid class name"
221:           @error_stream.puts m
222:           raise m
223:         end
224:         begin
225:           eval(name, binding, __FILE__, __LINE__)
226:         rescue NameError => e
227:           @error_stream.puts "Couldn't find #{kind} class #{name}"
228:           @error_stream.puts "Make sure the --require option is specified *before* #{option}"
229:           if $_spec_spec ; raise e ; else exit(1) ; end
230:         end
231:       end
set_spec_from_line_number()
     # File lib/spec/runner/options.rb, line 263
263:       def set_spec_from_line_number
264:         if examples.empty?
265:           if files.length == 1
266:             if File.directory?(files[0])
267:               error_stream.puts "You must specify one file, not a directory when using the --line option"
268:               exit(1) if stderr?
269:             else
270:               example = SpecParser.new.spec_name_for(files[0], line_number)
271:               @examples = [example]
272:             end
273:           else
274:             error_stream.puts "Only one file can be specified when using the --line option: #{files.inspect}"
275:             exit(3) if stderr?
276:           end
277:         else
278:           error_stream.puts "You cannot use both --line and --example"
279:           exit(4) if stderr?
280:         end
281:       end
sorted_files()
     # File lib/spec/runner/options.rb, line 250
250:       def sorted_files
251:         return sorter ? files.sort(&sorter) : files
252:       end
sorter()
     # File lib/spec/runner/options.rb, line 254
254:       def sorter
255:         FILE_SORTERS[loadby]
256:       end
stderr?()
     # File lib/spec/runner/options.rb, line 283
283:       def stderr?
284:         @error_stream == $stderr
285:       end