Permalink
Browse files

refactor expectation framework configuration in prep for adding support

for expecting with the assertion framework provided by stdlib
  • Loading branch information...
1 parent eef0b5c commit 578d977e1042598ee8e59ac5bb99613aa9920310 @dchelimsky dchelimsky committed Dec 5, 2010
Showing with 47 additions and 33 deletions.
  1. +30 −16 lib/rspec/core/configuration.rb
  2. +17 −17 spec/rspec/core/configuration_spec.rb
@@ -111,17 +111,17 @@ def cleaned_from_backtrace?(line)
backtrace_clean_patterns.any? { |regex| line =~ regex }
end
- # Delegates to mock_framework=(framework)
- def mock_with(framework)
- self.mock_framework = framework
- end
-
# Returns the configured mock framework adapter module
def mock_framework
settings[:mock_framework] ||= begin
- require 'rspec/core/mocking/with_rspec'
- RSpec::Core::MockFrameworkAdapter
- end
+ require 'rspec/core/mocking/with_rspec'
+ RSpec::Core::MockFrameworkAdapter
+ end
+ end
+
+ # Delegates to mock_framework=(framework)
+ def mock_with(framework)
+ self.mock_framework = framework
end
# Sets the mock framework adapter module.
@@ -168,14 +168,29 @@ def mock_framework=(framework)
end
end
- def expect_with(expectation_framework)
- settings[:expectation_framework] = expectation_framework
+ # Returns the configured expectation framework adapter module
+ def expectation_framework
+ settings[:expectation_framework] ||= begin
+ require 'rspec/core/expecting/with_rspec'
+ RSpec::Core::ExpectationFrameworkAdapter
+ end
+ end
+
+ # Delegates to expectation_framework=(framework)
+ def expect_with(framework)
+ self.expectation_framework = framework
end
- def require_expectation_framework_adapter
- require case expectation_framework.to_s
- when /rspec/i
- 'rspec/core/expecting/with_rspec'
+ # Sets the expectation framework module.
+ #
+ # +framework+ can be a Symbol or a Module.
+ #
+ # Given :rspec, configures rspec-expectations.
+ def expectation_framework=(framework)
+ case framework
+ when :rspec
+ require 'rspec/core/expecting/with_rspec'
+ settings[:expectation_framework] = RSpec::Core::ExpectationFrameworkAdapter
else
raise ArgumentError, "#{expectation_framework.inspect} is not supported"
end
@@ -355,8 +370,7 @@ def configure_mock_framework
end
def configure_expectation_framework
- require_expectation_framework_adapter
- RSpec::Core::ExampleGroup.send(:include, RSpec::Core::ExpectationFrameworkAdapter)
+ RSpec::Core::ExampleGroup.send(:include, expectation_framework)
end
def load_spec_files
@@ -30,10 +30,6 @@ module RSpec::Core
end
describe "#mock_framework" do
- before(:each) do
- config.stub(:require)
- end
-
it "defaults to :rspec" do
config.should_receive(:require).with('rspec/core/mocking/with_rspec')
config.mock_framework
@@ -52,6 +48,7 @@ module RSpec::Core
context "with a module" do
it "sets the mock_framework_adapter to that module" do
+ config.stub(:require)
mod = Module.new
config.mock_framework = mod
config.mock_framework.should eq(mod)
@@ -71,32 +68,35 @@ module RSpec::Core
end
end
- describe "expectation_framework" do
-
+ describe "#expectation_framework" do
it "defaults to :rspec" do
config.should_receive(:require).with('rspec/core/expecting/with_rspec')
- config.require_expectation_framework_adapter
+ config.expectation_framework
end
+ end
+ describe "#expectation_framework=" do
[:rspec].each do |framework|
- it "uses #{framework.inspect} framework when set explicitly" do
- config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
- config.expectation_framework = framework
- config.require_expectation_framework_adapter
+ context "with #{framework}" do
+ it "requires the adapter for #{framework.inspect}" do
+ config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
+ config.expectation_framework = framework
+ end
end
end
+ end
- it "supports expect_with for backward compatibility with rspec-1.x" do
- config.should_receive(:require).with('rspec/core/expecting/with_rspec')
+ describe "#expect_with" do
+ it "delegates to expectation_framework=" do
+ config.should_receive(:expectation_framework=).with(:rspec)
config.expect_with :rspec
- config.require_expectation_framework_adapter
end
it "raises ArgumentError if framework is not supported" do
- config.expectation_framework = :not_supported
- expect { config.require_expectation_framework_adapter }.to raise_error(ArgumentError)
+ expect do
+ config.expectation_framework = :not_supported
+ end.to raise_error(ArgumentError)
end
-
end
context "setting the files to run" do

0 comments on commit 578d977

Please sign in to comment.