Class | Spec::Runner::Options
In: | lib/spec/runner/options.rb
Parent: | Object

### Methods

add_example_group colour= custom_runner custom_runner? default_differ differ_class= examples_run? examples_should_be_run? examples_should_not_be_run files_to_load formatters heckle load_class load_formatters load_heckle_runner new number_of_examples parse_diff parse_example parse_format remove_example_group run_examples set_spec_from_line_number sorted_files sorter stderr? story_formatters

### 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

new(error_stream, output_stream)

[Source]

        # File 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

add_example_group(example_group)

[Source]

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

colour=(colour)

[Source]

         # File lib/spec/runner/options.rb, line 126
    126:       def colour=(colour)
    127:         @colour = colour
    128:         if @colour && RUBY_PLATFORM =~ /win32/ ;\
    129:           begin ;\
    130:             require 'rubygems' ;\
    131:             require 'Win32/Console/ANSI' ;\
    132:           rescue LoadError ;\
    133:             warn "You must 'gem install win32console' to use colour on Windows" ;\
    134:             @colour = false ;\
    135:           end
    136:         end
    137:       end

examples_run?()

[Source]

         # File lib/spec/runner/options.rb, line 118
    118:       def examples_run?
    119:         @examples_run
    120:       end

examples_should_not_be_run()

[Source]

         # File lib/spec/runner/options.rb, line 122
    122:       def examples_should_not_be_run
    123:         @examples_should_be_run = false
    124:       end

files_to_load()

[Source]

         # File lib/spec/runner/options.rb, line 208
    208:       def files_to_load
    209:         result = []
    210:         sorted_files.each do |file|
    211:           if File.directory?(file)
    212:             filename_pattern.split(",").each do |pattern|
    213:               result += Dir[File.expand_path("#{file}/#{pattern.strip}")]
    214:             end
    215:           elsif File.file?(file)
    216:             result << file
    217:           else
    218:             raise "File or directory not found: #{file}"
    219:           end
    220:         end
    221:         result
    222:       end

formatters()

[Source]

         # File lib/spec/runner/options.rb, line 172
    172:       def formatters
    173:         @format_options ||= [['progress', @output_stream]]
    174:         @formatters ||= load_formatters(@format_options, EXAMPLE_FORMATTERS)
    175:       end

load_formatters(format_options, formatters)

[Source]

         # File lib/spec/runner/options.rb, line 182
    182:       def load_formatters(format_options, formatters)
    183:         format_options.map do |format, where|
    184:           formatter_type = if formatters[format]
    185:             require formatters[format][0]
    186:             eval(formatters[format][1], binding, __FILE__, __LINE__)
    187:           else
    188:             load_class(format, 'formatter', '--format')
    189:           end
    190:           formatter_type.new(self, where)
    191:         end
    192:       end

load_heckle_runner(heckle)

[Source]

         # File lib/spec/runner/options.rb, line 194
    194:       def load_heckle_runner(heckle)
    195:         suffix = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? '_unsupported' : ''
    196:         require "spec/runner/heckle_runner#{suffix}"
    197:         @heckle_runner = HeckleRunner.new(heckle)
    198:       end

number_of_examples()

[Source]

         # File lib/spec/runner/options.rb, line 200
    200:       def number_of_examples
    201:         total = 0
    202:         @example_groups.each do |example_group|
    203:           total += example_group.number_of_examples
    204:         end
    205:         total
    206:       end

parse_diff(format)

[Source]

         # File lib/spec/runner/options.rb, line 139
    139:       def parse_diff(format)
    140:         case format
    141:         when :context, 'context', 'c'
    142:           @diff_format  = :context
    143:           default_differ
    144:         when :unified, 'unified', 'u', '', nil
    145:           @diff_format  = :unified
    146:           default_differ
    147:         else
    148:           @diff_format  = :custom
    149:           self.differ_class = load_class(format, 'differ', '--diff')
    150:         end
    151:       end

parse_example(example)

[Source]

         # File lib/spec/runner/options.rb, line 153
    153:       def parse_example(example)
    154:         if(File.file?(example))
    155:           @examples = File.open(example).read.split("\n")
    156:         else
    157:           @examples = [example]
    158:         end
    159:       end

parse_format(format_arg)

[Source]

         # File lib/spec/runner/options.rb, line 161
    161:       def parse_format(format_arg)
    162:         format, where = ClassAndArgumentsParser.parse(format_arg)
    163:         unless where
    164:           raise "When using several --format options only one of them can be without a file" if @out_used
    165:           where = @output_stream
    166:           @out_used = true
    167:         end
    168:         @format_options ||= []
    169:         @format_options << [format, where]
    170:       end

remove_example_group(example_group)

[Source]

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

run_examples()

[Source]

         # File 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:           before_suite_parts.each do |part|
     93:             part.call
     94:           end
     95:           runner = custom_runner || ExampleGroupRunner.new(self)
     96:
     97:           unless @files_loaded
     98:             runner.load_files(files_to_load)
     99:             @files_loaded = true
    100:           end
    101:
    102:           if example_groups.empty?
    103:             true
    104:           else
    105:             set_spec_from_line_number if line_number
    106:             success = runner.run
    107:             @examples_run = true
    108:             heckle if heckle_runner
    109:             success
    110:           end
    111:         ensure
    112:           after_suite_parts.each do |part|
    113:             part.call(success)
    114:           end
    115:         end
    116:       end

story_formatters()

[Source]

         # File lib/spec/runner/options.rb, line 177
    177:       def story_formatters
    178:         @format_options ||= [['plain', @output_stream]]
    179:         @formatters ||= load_formatters(@format_options, STORY_FORMATTERS)
    180:       end

### Protected Instance methods

custom_runner()

[Source]

         # File lib/spec/runner/options.rb, line 254
    254:       def custom_runner
    255:         return nil unless custom_runner?
    256:         klass_name, arg = ClassAndArgumentsParser.parse(user_input_for_runner)
    257:         runner_type = load_class(klass_name, 'behaviour runner', '--runner')
    258:         return runner_type.new(self, arg)
    259:       end

custom_runner?()

[Source]

         # File lib/spec/runner/options.rb, line 261
    261:       def custom_runner?
    262:         return user_input_for_runner ? true : false
    263:       end

default_differ()

[Source]

         # File lib/spec/runner/options.rb, line 279
    279:       def default_differ
    280:         require 'spec/expectations/differs/default'
    281:         self.differ_class = Spec::Expectations::Differs::Default
    282:       end

differ_class=(klass)

[Source]

         # File lib/spec/runner/options.rb, line 230
    230:       def differ_class=(klass)
    231:         return unless klass
    232:         @differ_class = klass
    233:         Spec::Expectations.differ = self.differ_class.new(self)
    234:       end

examples_should_be_run?()

[Source]

         # File lib/spec/runner/options.rb, line 225
    225:       def examples_should_be_run?
    226:         return @examples_should_be_run unless @examples_should_be_run.nil?
    227:         @examples_should_be_run = true
    228:       end

heckle()

[Source]

         # File lib/spec/runner/options.rb, line 265
    265:       def heckle
    266:         heckle_runner = self.heckle_runner
    267:         self.heckle_runner = nil
    268:         heckle_runner.heckle_with
    269:       end

load_class(name, kind, option)

[Source]

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

set_spec_from_line_number()

[Source]

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

sorted_files()

[Source]

         # File lib/spec/runner/options.rb, line 271
    271:       def sorted_files
    272:         return sorter ? files.sort(&sorter) : files
    273:       end

sorter()

[Source]

         # File lib/spec/runner/options.rb, line 275
    275:       def sorter
    276:         FILE_SORTERS[loadby]
    277:       end

stderr?()

[Source]

         # File lib/spec/runner/options.rb, line 304
    304:       def stderr?
    305:         @error_stream == $stderr
    306:       end

[Validate]