# File lib/spec/runner/options.rb, line 55 55: def initialize(error_stream, output_stream) 56: @error_stream = error_stream 57: @output_stream = output_stream 58: @filename_pattern = "**/*_spec.rb" 59: @backtrace_tweaker = QuietBacktraceTweaker.new 60: @examples = [] 61: @colour = false 62: @profile = false 63: @dry_run = false 64: @debug = false 65: @reporter = Reporter.new(self) 66: @context_lines = 3 67: @diff_format = :unified 68: @files = [] 69: @example_groups = [] 70: @result = nil 71: @examples_run = false 72: @examples_should_be_run = nil 73: @user_input_for_runner = nil 74: @after_suite_parts = [] 75: @files_loaded = false 76: @out_used = nil 77: end
# File lib/spec/runner/options.rb, line 79 79: def add_example_group(example_group) 80: @example_groups << example_group 81: end
# File lib/spec/runner/options.rb, line 168 168: def after_suite_parts 169: Spec::Example::BeforeAndAfterHooks.after_suite_parts 170: end
# File lib/spec/runner/options.rb, line 164 164: def before_suite_parts 165: Spec::Example::BeforeAndAfterHooks.before_suite_parts 166: end
# File lib/spec/runner/options.rb, line 185 185: def colour=(colour) 186: @colour = colour 187: if @colour && RUBY_PLATFORM =~ /mswin|mingw/ ; begin ; replace_output = @output_stream.equal?($stdout) ; require 'rubygems' unless ENV['NO_RUBYGEMS'] ; require 'Win32/Console/ANSI' ; @output_stream = $stdout if replace_output ; rescue LoadError ; warn "You must 'gem install win32console' to use colour on Windows" ; @colour = false ; end 188: end 189: end
# File lib/spec/runner/options.rb, line 293 293: def drb_port 294: @drb_port.to_i if defined?(@drb_port) 295: end
# File lib/spec/runner/options.rb, line 289 289: def dry_run? 290: @dry_run == true 291: end
# File lib/spec/runner/options.rb, line 87 87: def example_line 88: Spec::Runner::LineNumberQuery.new(self).example_line_for(files.first, line_number) 89: end
# File lib/spec/runner/options.rb, line 172 172: def examples_run? 173: @examples_run 174: end
# File lib/spec/runner/options.rb, line 176 176: def examples_should_not_be_run 177: @examples_should_be_run = false 178: end
# File lib/spec/runner/options.rb, line 273 273: def files_to_load 274: result = [] 275: sorted_files.each do |file| 276: if File.directory?(file) 277: filename_pattern.split(",").each do |pattern| 278: result += Dir[File.expand_path("#{file}/#{pattern.strip}")] 279: end 280: elsif File.file?(file) 281: result << file 282: else 283: raise "File or directory not found: #{file}" 284: end 285: end 286: result 287: end
# File lib/spec/runner/options.rb, line 250 250: def formatter_options 251: @formatter_options ||= OpenStruct.new( 252: :colour => colour, 253: :autospec => autospec, 254: :dry_run => dry_run 255: ) 256: end
# File lib/spec/runner/options.rb, line 233 233: def formatters 234: @format_options ||= [['progress', @output_stream]] 235: @formatters ||= load_formatters(@format_options, EXAMPLE_FORMATTERS) 236: end
# File lib/spec/runner/options.rb, line 83 83: def line_number_requested? 84: !!line_number 85: end
# File lib/spec/runner/options.rb, line 238 238: def load_formatters(format_options, formatters) 239: format_options.map do |format, where| 240: formatter_type = if formatters[format] 241: require formatters[format][0] 242: eval(formatters[format][1], binding, __FILE__, __LINE__) 243: else 244: load_class(format, 'formatter', '--format') 245: end 246: formatter_type.new(formatter_options, where) 247: end 248: end
# File lib/spec/runner/options.rb, line 262 262: def load_heckle_runner(heckle) 263: @format_options ||= [['silent', @output_stream]] 264: require which_heckle_runner 265: @heckle_runner = ::Spec::Runner::HeckleRunner.new(heckle) 266: end
# File lib/spec/runner/options.rb, line 180 180: def mock_framework 181: # TODO - don't like this dependency - perhaps store this in here instead? 182: Spec::Runner.configuration.mock_framework 183: end
# File lib/spec/runner/options.rb, line 268 268: def number_of_examples 269: return examples.size unless examples.empty? 270: @example_groups.inject(0) {|sum, group| sum + group.number_of_examples} 271: end
# File lib/spec/runner/options.rb, line 200 200: def parse_diff(format) 201: case format 202: when :context, 'context', 'c' 203: @diff_format = :context 204: default_differ 205: when :unified, 'unified', 'u', '', nil 206: @diff_format = :unified 207: default_differ 208: else 209: @diff_format = :custom 210: self.differ_class = load_class(format, 'differ', '--diff') 211: end 212: end
# File lib/spec/runner/options.rb, line 214 214: def parse_example(example) 215: if(File.file?(example)) 216: @examples = [File.open(example).read.split("\n")].flatten 217: else 218: @examples = [example] 219: end 220: end
# File lib/spec/runner/options.rb, line 222 222: def parse_format(format_arg) 223: format, where = ClassAndArgumentsParser.parse(format_arg) 224: unless where 225: raise "When using several --format options only one of them can be without a file" if @out_used 226: where = @output_stream 227: @out_used = true 228: end 229: @format_options ||= [] 230: @format_options << [format, where] 231: end
# File lib/spec/runner/options.rb, line 91 91: def remove_example_group(example_group) 92: @example_groups.delete(example_group) 93: end
# File lib/spec/runner/options.rb, line 95 95: def require_ruby_debug 96: require 'rubygems' unless ENV['NO_RUBYGEMS'] 97: require 'ruby-debug' 98: end
# File lib/spec/runner/options.rb, line 122 122: def run_examples 123: require_ruby_debug if debug 124: return true unless examples_should_be_run? 125: success = true 126: begin 127: runner = custom_runner || ExampleGroupRunner.new(self) 128: 129: unless @files_loaded 130: ['spec','lib'].each do |dir| 131: add_dir_from_project_root_to_load_path(dir) 132: end 133: runner.load_files(files_to_load) 134: @files_loaded = true 135: end 136: 137: define_predicate_matchers 138: plugin_mock_framework 139: ignore_backtrace_patterns 140: 141: # TODO - this has to happen after the files get loaded, 142: # otherwise the before_suite_parts are not populated 143: # from the configuration. There is no spec for this 144: # directly, but features/before_and_after_blocks/before_and_after_blocks.story 145: # will fail if this happens before the files are loaded. 146: before_suite_parts.each { |part| part.call } 147: 148: if example_groups.empty? 149: true 150: else 151: set_spec_from_line_number if line_number 152: success = runner.run 153: @examples_run = true 154: heckle if heckle_runner 155: success 156: end 157: ensure 158: after_suite_parts.each do |part| 159: part.arity < 1 ? part.call : part.call(success) 160: end 161: end 162: end
# File lib/spec/runner/options.rb, line 350 350: def custom_runner 351: return nil unless custom_runner? 352: klass_name, arg = ClassAndArgumentsParser.parse(user_input_for_runner) 353: runner_type = load_class(klass_name, 'example group runner', '--runner') 354: return runner_type.new(self, arg) 355: end
# File lib/spec/runner/options.rb, line 357 357: def custom_runner? 358: return user_input_for_runner ? true : false 359: end
# File lib/spec/runner/options.rb, line 375 375: def default_differ 376: require 'spec/runner/differs/default' 377: self.differ_class = ::Spec::Expectations::Differs::Default 378: end
# File lib/spec/runner/options.rb, line 299 299: def define_predicate_matchers 300: Spec::Runner.configuration.predicate_matchers.each_pair do |matcher_method, method_on_object| 301: Spec::Example::ExampleMethods::__send__ :define_method, matcher_method do |*args| 302: eval("be_#{method_on_object.to_s.gsub('?','')}(*args)") 303: end 304: end 305: end
# File lib/spec/runner/options.rb, line 326 326: def differ_class=(klass) 327: return unless klass 328: @differ_class = klass 329: Spec::Expectations.differ = self.differ_class.new(self) 330: end
# File lib/spec/runner/options.rb, line 321 321: def examples_should_be_run? 322: return @examples_should_be_run unless @examples_should_be_run.nil? 323: @examples_should_be_run = true 324: end
# File lib/spec/runner/options.rb, line 361 361: def heckle 362: heckle_runner = self.heckle_runner 363: self.heckle_runner = nil 364: heckle_runner.heckle_with 365: end
# File lib/spec/runner/options.rb, line 317 317: def ignore_backtrace_patterns 318: @backtrace_tweaker.ignore_patterns Spec::Runner.configuration.ignored_backtrace_patterns 319: end
# File lib/spec/runner/options.rb, line 332 332: def load_class(name, kind, option) 333: if name =~ /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ 334: arg = $2 == "" ? nil : $2 335: [$1, arg] 336: else 337: m = "#{name.inspect} is not a valid class name" 338: @error_stream.puts m 339: raise m 340: end 341: begin 342: eval(name, binding, __FILE__, __LINE__) 343: rescue NameError => e 344: @error_stream.puts "Couldn't find #{kind} class #{name}" 345: @error_stream.puts "Make sure the --require option is specified *before* #{option}" 346: if $_spec_spec ; raise e ; else exit(1) ; end 347: end 348: end
# File lib/spec/runner/options.rb, line 307 307: def plugin_mock_framework 308: case mock_framework 309: when Module 310: Spec::Example::ExampleMethods.__send__ :include, mock_framework 311: else 312: require mock_framework 313: Spec::Example::ExampleMethods.__send__ :include, Spec::Adapters::MockFramework 314: end 315: end
# File lib/spec/runner/options.rb, line 380 380: def set_spec_from_line_number 381: if examples.empty? 382: if files.length == 1 383: if File.directory?(files[0]) 384: error_stream.puts "You must specify one file, not a directory when providing a line number" 385: exit(1) if stderr? 386: else 387: example = LineNumberQuery.new(self).spec_name_for(files[0], line_number) 388: @examples = [example] 389: end 390: else 391: error_stream.puts "Only one file can be specified when providing a line number: #{files.inspect}" 392: exit(3) if stderr? 393: end 394: else 395: error_stream.puts "You cannot use --example and specify a line number" 396: exit(4) if stderr? 397: end 398: end
# File lib/spec/runner/options.rb, line 367 367: def sorted_files 368: return sorter ? files.sort(&sorter) : files 369: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.