Class Spec::Runner::Options
In: vendor/plugins/rspec/lib/spec/runner/options.rb
Parent: Object

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'], 'nested' => ['spec/runner/formatter/nested_text_formatter', 'Formatter::NestedTextFormatter'], 'n' => ['spec/runner/formatter/nested_text_formatter', 'Formatter::NestedTextFormatter'], '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

after_suite_parts  [RW] 
argv  [RW] 
backtrace_tweaker  [RW] 
before_suite_parts  [RW] 
colour  [R] 
context_lines  [RW] 
diff_format  [RW] 
differ_class  [R] 
dry_run  [RW] 
error_stream  [RW] 
example_groups  [R] 
examples  [RW] 
filename_pattern  [RW] 
files  [R] 
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  [RW] 

Public Class methods

[Source]

    # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 58
58:       def initialize(error_stream, output_stream)
59:         @error_stream = error_stream
60:         @output_stream = output_stream
61:         @filename_pattern = "**/*_spec.rb"
62:         @backtrace_tweaker = QuietBacktraceTweaker.new
63:         @examples = []
64:         @colour = false
65:         @profile = false
66:         @dry_run = false
67:         @reporter = Reporter.new(self)
68:         @context_lines = 3
69:         @diff_format  = :unified
70:         @files = []
71:         @example_groups = []
72:         @result = nil
73:         @examples_run = false
74:         @examples_should_be_run = nil
75:         @user_input_for_runner = nil
76:         @before_suite_parts = []
77:         @after_suite_parts = []
78:       end

Public Instance methods

[Source]

    # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 80
80:       def add_example_group(example_group)
81:         @example_groups << example_group
82:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 132
132:       def colour=(colour)
133:         @colour = colour
134:         if @colour && RUBY_PLATFORM =~ /mswin|mingw/ ;\
135:           begin ;\
136:             require 'rubygems' ;\
137:             require 'Win32/Console/ANSI' ;\
138:           rescue LoadError ;\
139:             warn "You must 'gem install win32console' to use colour on Windows" ;\
140:             @colour = false ;\
141:           end
142:         end
143:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 124
124:       def examples_run?
125:         @examples_run
126:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 128
128:       def examples_should_not_be_run
129:         @examples_should_be_run = false
130:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 214
214:       def files_to_load
215:         result = []
216:         sorted_files.each do |file|
217:           if File.directory?(file)
218:             filename_pattern.split(",").each do |pattern|
219:               result += Dir[File.expand_path("#{file}/#{pattern.strip}")]
220:             end
221:           elsif File.file?(file)
222:             result << file
223:           else
224:             raise "File or directory not found: #{file}"
225:           end
226:         end
227:         result
228:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 178
178:       def formatters
179:         @format_options ||= [['progress', @output_stream]]
180:         @formatters ||= load_formatters(@format_options, EXAMPLE_FORMATTERS)
181:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 188
188:       def load_formatters(format_options, formatters)
189:         format_options.map do |format, where|
190:           formatter_type = if formatters[format]
191:             require formatters[format][0]
192:             eval(formatters[format][1], binding, __FILE__, __LINE__)
193:           else
194:             load_class(format, 'formatter', '--format')
195:           end
196:           formatter_type.new(self, where)
197:         end
198:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 200
200:       def load_heckle_runner(heckle)
201:         suffix = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? '_unsupported' : ''
202:         require "spec/runner/heckle_runner#{suffix}"
203:         @heckle_runner = HeckleRunner.new(heckle)
204:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 206
206:       def number_of_examples
207:         total = 0
208:         @example_groups.each do |example_group|
209:           total += example_group.number_of_examples
210:         end
211:         total
212:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 145
145:       def parse_diff(format)
146:         case format
147:         when :context, 'context', 'c'
148:           @diff_format  = :context
149:           default_differ
150:         when :unified, 'unified', 'u', '', nil
151:           @diff_format  = :unified
152:           default_differ
153:         else
154:           @diff_format  = :custom
155:           self.differ_class = load_class(format, 'differ', '--diff')
156:         end
157:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 159
159:       def parse_example(example)
160:         if(File.file?(example))
161:           @examples = File.open(example).read.split("\n")
162:         else
163:           @examples = [example]
164:         end
165:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 167
167:       def parse_format(format_arg)
168:         format, where = ClassAndArgumentsParser.parse(format_arg)
169:         unless where
170:           raise "When using several --format options only one of them can be without a file" if @out_used
171:           where = @output_stream
172:           @out_used = true
173:         end
174:         @format_options ||= []
175:         @format_options << [format, where]
176:       end

[Source]

    # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 84
84:       def remove_example_group(example_group)
85:         @example_groups.delete(example_group)
86:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 88
 88:       def run_examples
 89:         return true unless examples_should_be_run?
 90:         success = true
 91:         begin
 92:           runner = custom_runner || ExampleGroupRunner.new(self)
 93: 
 94:           unless @files_loaded
 95:             runner.load_files(files_to_load)
 96:             @files_loaded = true
 97:           end
 98: 
 99:           # TODO - this has to happen after the files get loaded,
100:           # otherwise the before_suite_parts are not populated
101:           # from the configuration. There is no spec for this
102:           # directly, but stories/configuration/before_blocks.story
103:           # will fail if this happens before the files are loaded.
104:           before_suite_parts.each do |part|
105:             part.call
106:           end
107: 
108:           if example_groups.empty?
109:             true
110:           else
111:             set_spec_from_line_number if line_number
112:             success = runner.run
113:             @examples_run = true
114:             heckle if heckle_runner
115:             success
116:           end
117:         ensure
118:           after_suite_parts.each do |part|
119:             part.call(success)
120:           end
121:         end
122:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 183
183:       def story_formatters
184:         @format_options ||= [['plain', @output_stream]]
185:         @formatters ||= load_formatters(@format_options, STORY_FORMATTERS)
186:       end

Protected Instance methods

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 260
260:       def custom_runner
261:         return nil unless custom_runner?
262:         klass_name, arg = ClassAndArgumentsParser.parse(user_input_for_runner)
263:         runner_type = load_class(klass_name, 'behaviour runner', '--runner')
264:         return runner_type.new(self, arg)
265:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 267
267:       def custom_runner?
268:         return user_input_for_runner ? true : false
269:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 285
285:       def default_differ
286:         require 'spec/expectations/differs/default'
287:         self.differ_class = Spec::Expectations::Differs::Default
288:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 236
236:       def differ_class=(klass)
237:         return unless klass
238:         @differ_class = klass
239:         Spec::Expectations.differ = self.differ_class.new(self)
240:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 231
231:       def examples_should_be_run?
232:         return @examples_should_be_run unless @examples_should_be_run.nil?
233:         @examples_should_be_run = true
234:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 271
271:       def heckle
272:         heckle_runner = self.heckle_runner
273:         self.heckle_runner = nil
274:         heckle_runner.heckle_with
275:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 242
242:       def load_class(name, kind, option)
243:         if name =~ /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/
244:           arg = $2 == "" ? nil : $2
245:           [$1, arg]
246:         else
247:           m = "#{name.inspect} is not a valid class name"
248:           @error_stream.puts m
249:           raise m
250:         end
251:         begin
252:           eval(name, binding, __FILE__, __LINE__)
253:         rescue NameError => e
254:           @error_stream.puts "Couldn't find #{kind} class #{name}"
255:           @error_stream.puts "Make sure the --require option is specified *before* #{option}"
256:           if $_spec_spec ; raise e ; else exit(1) ; end
257:         end
258:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 290
290:       def set_spec_from_line_number
291:         if examples.empty?
292:           if files.length == 1
293:             if File.directory?(files[0])
294:               error_stream.puts "You must specify one file, not a directory when using the --line option"
295:               exit(1) if stderr?
296:             else
297:               example = SpecParser.new.spec_name_for(files[0], line_number)
298:               @examples = [example]
299:             end
300:           else
301:             error_stream.puts "Only one file can be specified when using the --line option: #{files.inspect}"
302:             exit(3) if stderr?
303:           end
304:         else
305:           error_stream.puts "You cannot use both --line and --example"
306:           exit(4) if stderr?
307:         end
308:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 277
277:       def sorted_files
278:         return sorter ? files.sort(&sorter) : files
279:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 281
281:       def sorter
282:         FILE_SORTERS[loadby]
283:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/runner/options.rb, line 310
310:       def stderr?
311:         @error_stream == $stderr
312:       end

[Validate]