lib/spec/runner/options.rb in dchelimsky-rspec-1.1.12 vs lib/spec/runner/options.rb in dchelimsky-rspec-1.1.99.1
- old
+ new
@@ -21,20 +21,10 @@
'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']
-
- }
-
attr_accessor(
:filename_pattern,
:backtrace_tweaker,
:context_lines,
:diff_format,
@@ -92,15 +82,18 @@
unless @files_loaded
runner.load_files(files_to_load)
@files_loaded = true
end
+
+ define_predicate_matchers
+ plugin_mock_framework
# 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
+ # directly, but features/before_and_after_blocks/before_and_after_blocks.story
# will fail if this happens before the files are loaded.
before_suite_parts.each do |part|
part.call
end
@@ -113,11 +106,11 @@
heckle if heckle_runner
success
end
ensure
after_suite_parts.each do |part|
- part.call(success)
+ part.arity < 1 ? part.call : part.call(success)
end
end
end
def before_suite_parts
@@ -134,15 +127,10 @@
def examples_should_not_be_run
@examples_should_be_run = false
end
- def predicate_matchers
- # TODO - don't like this dependency - perhaps store these in here instead?
- Spec::Runner.configuration.predicate_matchers
- end
-
def mock_framework
# TODO - don't like this dependency - perhaps store this in here instead?
Spec::Runner.configuration.mock_framework
end
@@ -197,15 +185,10 @@
def formatters
@format_options ||= [['progress', @output_stream]]
@formatters ||= load_formatters(@format_options, EXAMPLE_FORMATTERS)
end
- def story_formatters
- @format_options ||= [['plain', @output_stream]]
- @formatters ||= load_formatters(@format_options, STORY_FORMATTERS)
- end
-
def load_formatters(format_options, formatters)
format_options.map do |format, where|
formatter_type = if formatters[format]
require formatters[format][0]
eval(formatters[format][1], binding, __FILE__, __LINE__)
@@ -215,13 +198,13 @@
formatter_type.new(self, where)
end
end
def load_heckle_runner(heckle)
- suffix = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? '_unsupported' : ''
+ suffix = ([/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} || Spec::Ruby.version.to_f == 1.9) ? '_unsupported' : ''
require "spec/runner/heckle_runner#{suffix}"
- @heckle_runner = HeckleRunner.new(heckle)
+ @heckle_runner = ::Spec::Runner::HeckleRunner.new(heckle)
end
def number_of_examples
return examples.size unless examples.empty?
@example_groups.inject(0) {|sum, group| sum + group.number_of_examples}
@@ -245,11 +228,30 @@
def dry_run?
@dry_run == true
end
- protected
+ protected
+
+ def define_predicate_matchers
+ Spec::Runner.configuration.predicate_matchers.each_pair do |matcher_method, method_on_object|
+ Spec::Example::ExampleMethods::__send__ :define_method, matcher_method do |*args|
+ eval("be_#{method_on_object.to_s.gsub('?','')}(*args)")
+ end
+ end
+ end
+
+ def plugin_mock_framework
+ case mock_framework
+ when Module
+ Spec::Example::ExampleMethods.__send__ :include, mock_framework
+ else
+ require mock_framework
+ Spec::Example::ExampleMethods.__send__ :include, Spec::Adapters::MockFramework
+ end
+ end
+
def examples_should_be_run?
return @examples_should_be_run unless @examples_should_be_run.nil?
@examples_should_be_run = true
end
@@ -302,10 +304,10 @@
FILE_SORTERS[loadby]
end
def default_differ
require 'spec/expectations/differs/default'
- self.differ_class = Spec::Expectations::Differs::Default
+ self.differ_class = ::Spec::Expectations::Differs::Default
end
def set_spec_from_line_number
if examples.empty?
if files.length == 1