Class: Spec::Runner::Options
- Defined in:
- lib/gems/rspec-1.1.12/lib/spec/runner/options.rb
Constant Summary collapse
- FILE_SORTERS =
{ 'mtime' => lambda {|file_a, file_b| File.mtime(file_b) <=> File.mtime(file_a)} }
- EXAMPLE_FORMATTERS =
Load these lazily for better speed
{ # 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'], 'progress' => ['spec/runner/formatter/story/progress_bar_formatter', 'Formatter::Story::ProgressBarFormatter'], 'r' => ['spec/runner/formatter/story/progress_bar_formatter', 'Formatter::Story::ProgressBarFormatter'] }
Instance Attribute Summary collapse
-
#argv ⇒ Object
Returns the value of attribute argv.
-
#backtrace_tweaker ⇒ Object
Returns the value of attribute backtrace_tweaker.
-
#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
readonly
Returns the value of attribute differ_class.
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#error_stream ⇒ Object
Returns the value of attribute error_stream.
-
#example_groups ⇒ Object
readonly
Returns the value of attribute example_groups.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#filename_pattern ⇒ Object
Returns the value of attribute filename_pattern.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#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.
-
#output_stream ⇒ Object
Returns the value of attribute output_stream.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#reporter ⇒ Object
Returns the value of attribute reporter.
-
#reverse ⇒ Object
Returns the value of attribute reverse.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#user_input_for_runner ⇒ Object
Returns the value of attribute user_input_for_runner.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #add_example_group(example_group) ⇒ Object
- #after_suite_parts ⇒ Object
- #before_suite_parts ⇒ Object
- #dry_run? ⇒ Boolean
- #examples_run? ⇒ Boolean
- #examples_should_not_be_run ⇒ Object
- #files_to_load ⇒ Object
- #formatters ⇒ Object
-
#initialize(error_stream, output_stream) ⇒ Options
constructor
A new instance of Options.
- #load_formatters(format_options, formatters) ⇒ Object
- #load_heckle_runner(heckle) ⇒ Object
- #mock_framework ⇒ Object
- #number_of_examples ⇒ Object
- #parse_diff(format) ⇒ Object
- #parse_example(example) ⇒ Object
- #parse_format(format_arg) ⇒ Object
- #predicate_matchers ⇒ Object
- #remove_example_group(example_group) ⇒ Object
- #run_examples ⇒ Object
- #story_formatters ⇒ Object
Constructor Details
#initialize(error_stream, output_stream) ⇒ Options
Returns a new instance of Options.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 58 def initialize(error_stream, output_stream) @error_stream = error_stream @output_stream = output_stream @filename_pattern = "**/*_spec.rb" @backtrace_tweaker = QuietBacktraceTweaker.new @examples = [] @colour = false @profile = false @dry_run = false @reporter = Reporter.new(self) @context_lines = 3 @diff_format = :unified @files = [] @example_groups = [] @result = nil @examples_run = false @examples_should_be_run = nil @user_input_for_runner = nil @after_suite_parts = [] end |
Instance Attribute Details
#argv ⇒ Object
Returns the value of attribute argv.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def argv @argv end |
#backtrace_tweaker ⇒ Object
Returns the value of attribute backtrace_tweaker.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def backtrace_tweaker @backtrace_tweaker end |
#colour ⇒ Object
Returns the value of attribute colour.
56 57 58 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 56 def colour @colour end |
#context_lines ⇒ Object
Returns the value of attribute context_lines.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def context_lines @context_lines end |
#diff_format ⇒ Object
Returns the value of attribute diff_format.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def diff_format @diff_format end |
#differ_class ⇒ Object
Returns the value of attribute differ_class.
56 57 58 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 56 def differ_class @differ_class end |
#dry_run ⇒ Object
Returns the value of attribute dry_run.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def dry_run @dry_run end |
#error_stream ⇒ Object
Returns the value of attribute error_stream.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def error_stream @error_stream end |
#example_groups ⇒ Object (readonly)
Returns the value of attribute example_groups.
56 57 58 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 56 def example_groups @example_groups end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
56 57 58 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 56 def examples @examples end |
#filename_pattern ⇒ Object
Returns the value of attribute filename_pattern.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def filename_pattern @filename_pattern end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
56 57 58 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 56 def files @files end |
#heckle_runner ⇒ Object
Returns the value of attribute heckle_runner.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def heckle_runner @heckle_runner end |
#line_number ⇒ Object
Returns the value of attribute line_number.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def line_number @line_number end |
#loadby ⇒ Object
Returns the value of attribute loadby.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def loadby @loadby end |
#output_stream ⇒ Object
Returns the value of attribute output_stream.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def output_stream @output_stream end |
#profile ⇒ Object
Returns the value of attribute profile.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def profile @profile end |
#reporter ⇒ Object
Returns the value of attribute reporter.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def reporter @reporter end |
#reverse ⇒ Object
Returns the value of attribute reverse.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def reverse @reverse end |
#timeout ⇒ Object
Returns the value of attribute timeout.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def timeout @timeout end |
#user_input_for_runner ⇒ Object
Returns the value of attribute user_input_for_runner.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def user_input_for_runner @user_input_for_runner end |
#verbose ⇒ Object
Returns the value of attribute verbose.
36 37 38 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 36 def verbose @verbose end |
Instance Method Details
#add_example_group(example_group) ⇒ Object
79 80 81 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 79 def add_example_group(example_group) @example_groups << example_group end |
#after_suite_parts ⇒ Object
127 128 129 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 127 def after_suite_parts Spec::Example::BeforeAndAfterHooks.after_suite_parts end |
#before_suite_parts ⇒ Object
123 124 125 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 123 def before_suite_parts Spec::Example::BeforeAndAfterHooks.before_suite_parts end |
#dry_run? ⇒ Boolean
246 247 248 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 246 def dry_run? @dry_run == true end |
#examples_run? ⇒ Boolean
131 132 133 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 131 def examples_run? @examples_run end |
#examples_should_not_be_run ⇒ Object
135 136 137 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 135 def examples_should_not_be_run @examples_should_be_run = false end |
#files_to_load ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 230 def files_to_load result = [] sorted_files.each do |file| if File.directory?(file) filename_pattern.split(",").each do |pattern| result += Dir[File.("#{file}/#{pattern.strip}")] end elsif File.file?(file) result << file else raise "File or directory not found: #{file}" end end result end |
#formatters ⇒ Object
197 198 199 200 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 197 def formatters @format_options ||= [['progress', @output_stream]] @formatters ||= load_formatters(@format_options, EXAMPLE_FORMATTERS) end |
#load_formatters(format_options, formatters) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 207 def load_formatters(, formatters) .map do |format, where| formatter_type = if formatters[format] require formatters[format][0] eval(formatters[format][1], binding, __FILE__, __LINE__) else load_class(format, 'formatter', '--format') end formatter_type.new(self, where) end end |
#load_heckle_runner(heckle) ⇒ Object
219 220 221 222 223 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 219 def load_heckle_runner(heckle) suffix = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? '_unsupported' : '' require "spec/runner/heckle_runner#{suffix}" @heckle_runner = HeckleRunner.new(heckle) end |
#mock_framework ⇒ Object
144 145 146 147 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 144 def mock_framework # TODO - don't like this dependency - perhaps store this in here instead? Spec::Runner.configuration.mock_framework end |
#number_of_examples ⇒ Object
225 226 227 228 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 225 def number_of_examples return examples.size unless examples.empty? @example_groups.inject(0) {|sum, group| sum + group.number_of_examples} end |
#parse_diff(format) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 164 def parse_diff(format) case format when :context, 'context', 'c' @diff_format = :context default_differ when :unified, 'unified', 'u', '', nil @diff_format = :unified default_differ else @diff_format = :custom self.differ_class = load_class(format, 'differ', '--diff') end end |
#parse_example(example) ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 178 def parse_example(example) if(File.file?(example)) @examples = [File.open(example).read.split("\n")].flatten else @examples = [example] end end |
#parse_format(format_arg) ⇒ Object
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 186 def parse_format(format_arg) format, where = ClassAndArgumentsParser.parse(format_arg) unless where raise "When using several --format options only one of them can be without a file" if @out_used where = @output_stream @out_used = true end @format_options ||= [] @format_options << [format, where] end |
#predicate_matchers ⇒ Object
139 140 141 142 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 139 def predicate_matchers # TODO - don't like this dependency - perhaps store these in here instead? Spec::Runner.configuration.predicate_matchers end |
#remove_example_group(example_group) ⇒ Object
83 84 85 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 83 def remove_example_group(example_group) @example_groups.delete(example_group) end |
#run_examples ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 87 def run_examples return true unless examples_should_be_run? success = true begin runner = custom_runner || ExampleGroupRunner.new(self) unless @files_loaded runner.load_files(files_to_load) @files_loaded = true end # TODO - this has to happen after the files get loaded, # otherwise the before_suite_parts are not populated # from the configuration. There is no spec for this # directly, but stories/configuration/before_blocks.story # will fail if this happens before the files are loaded. before_suite_parts.each do |part| part.call end if example_groups.empty? true else set_spec_from_line_number if line_number success = runner.run @examples_run = true heckle if heckle_runner success end ensure after_suite_parts.each do |part| part.call(success) end end end |
#story_formatters ⇒ Object
202 203 204 205 |
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/options.rb', line 202 def story_formatters @format_options ||= [['plain', @output_stream]] @formatters ||= load_formatters(@format_options, STORY_FORMATTERS) end |