diff options
Diffstat (limited to 'vendor/plugins/rspec/spec/spec_helper.rb')
-rw-r--r-- | vendor/plugins/rspec/spec/spec_helper.rb | 147 |
1 files changed, 78 insertions, 69 deletions
diff --git a/vendor/plugins/rspec/spec/spec_helper.rb b/vendor/plugins/rspec/spec/spec_helper.rb index 1318176d5..3cffe875d 100644 --- a/vendor/plugins/rspec/spec/spec_helper.rb +++ b/vendor/plugins/rspec/spec/spec_helper.rb @@ -1,18 +1,24 @@ require 'stringio' -dir = File.dirname(__FILE__) -lib_path = File.expand_path("#{dir}/../lib") -$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path) $_spec_spec = true # Prevents Kernel.exit in various places require 'spec' require 'spec/mocks' -require 'spec/story' -spec_classes_path = File.expand_path("#{dir}/../spec/spec/spec_classes") -require spec_classes_path unless $LOAD_PATH.include?(spec_classes_path) -require File.dirname(__FILE__) + '/../lib/spec/expectations/differs/default' +require 'spec/runner/differs/default' +require 'spec/autorun' + +require 'support/spec_classes' +require 'support/macros' + +def jruby? + ::RUBY_PLATFORM == 'java' +end + +module Spec + module Example + class NonStandardError < Exception; end + end -module Spec module Matchers def fail raise_error(Spec::Expectations::ExpectationNotMetError) @@ -22,82 +28,85 @@ module Spec raise_error(Spec::Expectations::ExpectationNotMetError, message) end - class Pass - def matches?(proc, &block) - begin - proc.call - true - rescue Exception => @error - false - end - end - - def failure_message - @error.message + "\n" + @error.backtrace.join("\n") + def exception_from(&block) + exception = nil + begin + yield + rescue StandardError => e + exception = e end - end - - def pass - Pass.new + exception end - class CorrectlyOrderedMockExpectation - def initialize(&event) - @event = event - end - - def expect(&expectations) - expectations.call - @event.call - end - end - - def during(&block) - CorrectlyOrderedMockExpectation.new(&block) - end - end -end - -class NonStandardError < Exception; end - -module Custom - class ExampleGroupRunner - attr_reader :options, :arg - def initialize(options, arg) - @options, @arg = options, arg + def run_with(options) + ::Spec::Runner::CommandLine.run(options) end - def load_files(files) + def with_ruby(version) + yield if RUBY_VERSION =~ Regexp.compile("^#{version.to_s}") end - - def run - end - end -end - -def exception_from(&block) - exception = nil - begin - yield - rescue StandardError => e - exception = e end - exception end -describe "sandboxed rspec_options", :shared => true do +def with_sandboxed_options attr_reader :options + + before(:each) do + @original_rspec_options = ::Spec::Runner.options + ::Spec::Runner.use(@options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)) + end - before(:all) do - @original_rspec_options = $rspec_options + after(:each) do + ::Spec::Runner.use(@original_rspec_options) end + + yield +end +def with_sandboxed_config + attr_reader :config + before(:each) do - @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new) - $rspec_options = options + @config = ::Spec::Runner::Configuration.new + @original_configuration = ::Spec::Runner.configuration + spec_configuration = @config + ::Spec::Runner.instance_eval {@configuration = spec_configuration} end + + after(:each) do + original_configuration = @original_configuration + ::Spec::Runner.instance_eval {@configuration = original_configuration} + ::Spec::Example::ExampleGroupFactory.reset + end + + yield +end - after do - $rspec_options = @original_rspec_options +module Spec + module Example + module Resettable + def reset # :nodoc: + @before_all_parts = nil + @after_all_parts = nil + @before_each_parts = nil + @after_each_parts = nil + end + end + class ExampleGroup + extend Resettable + end + class ExampleGroupDouble < ExampleGroup + ::Spec::Runner.options.remove_example_group self + def register_example_group(klass) + #ignore + end + def initialize(proxy=nil, &block) + super(proxy || ExampleProxy.new, &block) + end + end end +end + +Spec::Runner.configure do |config| + config.extend(Macros) end
\ No newline at end of file |