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] | |
behaviour_runner | [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_arg | [RW] | |
timeout | [RW] | |
verbose | [RW] |
# File lib/spec/runner/options.rb, line 41 41: def initialize(err, out) 42: @err, @out = err, out 43: @backtrace_tweaker = QuietBacktraceTweaker.new 44: @examples = [] 45: @formatters = [] 46: @colour = false 47: @dry_run = false 48: end
# File lib/spec/runner/options.rb, line 50 50: def configure 51: configure_formatters 52: create_reporter 53: configure_differ 54: create_behaviour_runner 55: end
# File lib/spec/runner/options.rb, line 79 79: def configure_differ 80: if @differ_class 81: Spec::Expectations.differ = @differ_class.new(@diff_format, @context_lines, @colour) 82: end 83: end
# File lib/spec/runner/options.rb, line 68 68: def configure_formatters 69: @formatters.each do |formatter| 70: formatter.colour = @colour if formatter.respond_to?(:colour=) 71: formatter.dry_run = @dry_run if formatter.respond_to?(:dry_run=) 72: end 73: end
# File lib/spec/runner/options.rb, line 57 57: def create_behaviour_runner 58: return nil if @generate 59: @behaviour_runner = if @runner_arg 60: klass_name, arg = split_at_colon(@runner_arg) 61: runner_type = load_class(klass_name, 'behaviour runner', '--runner') 62: runner_type.new(self, arg) 63: else 64: BehaviourRunner.new(self) 65: end 66: end
# File lib/spec/runner/options.rb, line 75 75: def create_reporter 76: @reporter = Reporter.new(@formatters, @backtrace_tweaker) 77: end
# File lib/spec/runner/options.rb, line 156 156: def load_class(name, kind, option) 157: if name =~ /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ 158: arg = $2 == "" ? nil : $2 159: [$1, arg] 160: else 161: m = "#{name.inspect} is not a valid class name" 162: @err.puts m 163: raise m 164: end 165: begin 166: eval(name, binding, __FILE__, __LINE__) 167: rescue NameError => e 168: @err.puts "Couldn't find #{kind} class #{name}" 169: @err.puts "Make sure the --require option is specified *before* #{option}" 170: if $_spec_spec ; raise e ; else exit(1) ; end 171: end 172: end
# File lib/spec/runner/options.rb, line 85 85: def parse_diff(format) 86: @context_lines = 3 87: case format 88: when :context, 'context', 'c' 89: @diff_format = :context 90: when :unified, 'unified', 'u', '', nil 91: @diff_format = :unified 92: end 93: 94: if [:context,:unified].include? @diff_format 95: require 'spec/expectations/differs/default' 96: @differ_class = Spec::Expectations::Differs::Default 97: else 98: @diff_format = :custom 99: @differ_class = load_class(format, 'differ', '--diff') 100: end 101: end
# File lib/spec/runner/options.rb, line 103 103: def parse_example(example) 104: if(File.file?(example)) 105: @examples = File.open(example).read.split("\n") 106: else 107: @examples = [example] 108: end 109: end
# File lib/spec/runner/options.rb, line 111 111: def parse_format(format_arg) 112: format, where = split_at_colon(format_arg) 113: # This funky regexp checks whether we have a FILE_NAME or not 114: if where.nil? 115: raise "When using several --format options only one of them can be without a file" if @out_used 116: where = @out 117: @out_used = true 118: end 119: 120: formatter_type = BUILT_IN_FORMATTERS[format] || load_class(format, 'formatter', '--format') 121: @formatters << formatter_type.new(where) 122: end
# File lib/spec/runner/options.rb, line 134 134: def parse_generate_options(options_file, args_copy, out_stream) 135: # Remove the --generate-options option and the argument before writing to file 136: index = args_copy.index("-G") || args_copy.index("--generate-options") 137: args_copy.delete_at(index) 138: args_copy.delete_at(index) 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 128 128: def parse_heckle(heckle) 129: heckle_require = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? 'spec/runner/heckle_runner_unsupported' : 'spec/runner/heckle_runner' 130: require heckle_require 131: @heckle_runner = HeckleRunner.new(heckle) 132: end
# File lib/spec/runner/options.rb, line 124 124: def parse_require(req) 125: req.split(",").each{|file| require file} 126: end