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