spec/rspec/mocks_spec.rb in rspec-mocks-2.99.0.beta1 vs spec/rspec/mocks_spec.rb in rspec-mocks-2.99.0.beta2
- old
+ new
@@ -1,33 +1,44 @@
require "spec_helper"
describe RSpec::Mocks do
describe "::setup" do
+ it "prints a deprecation warning when given a non-rspec host" do
+ o = Object.new
+ expect(RSpec).to receive(:deprecate).with(
+ "The host argument to `RSpec::Mocks.setup`",
+ :replacement=>"`include RSpec::Mocks::ExampleMethods` in #{o}"
+ )
+ RSpec::Mocks::setup(o)
+ end
+
+ it "prints the deprecation warning with the correct line" do
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
+ RSpec::Mocks::setup(Object.new)
+ end
+
+ it "does not print a deprecation warning when self (the example group) is passed." do
+ expect(RSpec).not_to receive(:deprecate)
+ RSpec::Mocks::setup(self)
+ end
+
context "with an existing Mock::Space" do
before do
@orig_space = RSpec::Mocks::space
end
after do
RSpec::Mocks::space = @orig_space
end
it "memoizes the space" do
- RSpec::Mocks::setup(Object.new)
+ RSpec::Mocks::setup
space = RSpec::Mocks::space
- RSpec::Mocks::setup(Object.new)
+ RSpec::Mocks::setup
expect(RSpec::Mocks::space).to equal(space)
end
end
-
- context "with no pre-existing Mock::Space" do
- it "initializes a Mock::Space" do
- RSpec::Mocks::space = nil
- RSpec::Mocks::setup(Object.new)
- expect(RSpec::Mocks::space).not_to be_nil
- end
- end
end
describe "::verify" do
it "delegates to the space" do
foo = double
@@ -38,15 +49,14 @@
end
end
describe "::teardown" do
it "delegates to the space" do
- foo = double
- foo.should_receive(:bar)
- RSpec::Mocks::teardown
- expect do
- foo.bar
- end.to raise_error(/received unexpected message/)
+ foo = "foo"
+ foo.stub(:reverse) { "reversed" }
+ RSpec::Mocks.teardown
+ RSpec::Mocks.setup
+ expect(foo.reverse).to eq("oof")
end
end
describe ".configuration" do
it 'returns a memoized configuration instance' do