Permalink
Browse files

align mock_with/mock_framework= with expect_with/expectation_framework=

One of each pair delegates to the other, but they were backward from
each other.
  • Loading branch information...
dchelimsky committed Oct 29, 2011
1 parent 11c80ba commit 659887ef803167c3f027b38dbf78c9c06a197982
Showing with 21 additions and 26 deletions.
  1. +6 −5 lib/rspec/core/configuration.rb
  2. +15 −21 spec/rspec/core/configuration_spec.rb
@@ -67,6 +67,7 @@ def self.add_setting(name, opts={})
def initialize
@expectation_frameworks = []
@include_or_extend_modules = []
+ @mock_framework = nil
@files_to_run = []
@formatters = []
@color_enabled = false
@@ -142,8 +143,8 @@ def mock_framework
end
# Delegates to mock_framework=(framework)
- def mock_with(framework)
- self.mock_framework = framework
+ def mock_framework=(framework)
+ mock_with framework
end
# Sets the mock framework adapter module.
@@ -168,7 +169,7 @@ def mock_with(framework)
#
# teardown_mocks_for_rspec
# - called after verify_mocks_for_rspec (even if there are errors)
- def mock_framework=(framework)
+ def mock_with(framework)
assert_no_example_groups_defined(:mock_framework)
case framework
when Module
@@ -196,9 +197,9 @@ def expectation_frameworks
@expectation_frameworks
end
- # Delegates to expect_with([framework])
+ # Delegates to expect_with(framework)
def expectation_framework=(framework)
- expect_with([framework])
+ expect_with(framework)
end
# Sets the expectation framework module(s).
@@ -48,12 +48,19 @@ module RSpec::Core
end
end
- describe "#mock_framework=" do
+ describe "#mock_framework="do
+ it "delegates to mock_with" do
+ config.should_receive(:mock_with).with(:rspec)
+ config.mock_with :rspec
+ end
+ end
+
+ describe "#mock_with" do
[:rspec, :mocha, :rr, :flexmock].each do |framework|
context "with #{framework}" do
it "requires the adapter for #{framework.inspect}" do
config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
- config.mock_framework = framework
+ config.mock_with framework
end
end
end
@@ -62,36 +69,26 @@ module RSpec::Core
it "sets the mock_framework_adapter to that module" do
config.stub(:require)
mod = Module.new
- config.mock_framework = mod
+ config.mock_with mod
config.mock_framework.should eq(mod)
end
end
it "uses the null adapter when set to any unknown key" do
config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
- config.mock_framework = :crazy_new_mocking_framework_ive_not_yet_heard_of
+ config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
end
context 'when there are already some example groups defined' do
- before(:each) do
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
- end
-
it 'raises an error since this setting must be applied before any groups are defined' do
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
expect {
- config.mock_framework = :rspec
+ config.mock_with :rspec
}.to raise_error(/must be configured before any example groups are defined/)
end
end
end
- describe "#mock_with" do
- it "delegates to mock_framework=" do
- config.should_receive(:mock_framework=).with(:rspec)
- config.mock_with :rspec
- end
- end
-
describe "#expectation_framework" do
it "defaults to :rspec" do
config.should_receive(:require).with('rspec/core/expecting/with_rspec')
@@ -101,7 +98,7 @@ module RSpec::Core
describe "#expectation_framework=" do
it "delegates to expect_with=" do
- config.should_receive(:expect_with).with([:rspec])
+ config.should_receive(:expect_with).with(:rspec)
config.expectation_framework = :rspec
end
end
@@ -123,11 +120,8 @@ module RSpec::Core
end
context 'when there are already some example groups defined' do
- before(:each) do
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
- end
-
it 'raises an error since this setting must be applied before any groups are defined' do
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
expect {
config.expect_with :rspec
}.to raise_error(/must be configured before any example groups are defined/)

0 comments on commit 659887e

Please sign in to comment.