Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure that any_instance doesn't interfere with other expectations se…

…t on the class
  • Loading branch information...
commit 6f517ff2bd3c5b2ce5f47f713fa89a7e416947f6 1 parent 6680e3c
@kaiwren kaiwren authored
Showing with 21 additions and 9 deletions.
  1. +21 −9 spec/rspec/mocks/any_instance_spec.rb
View
30 spec/rspec/mocks/any_instance_spec.rb
@@ -221,6 +221,27 @@ class RSpec::SampleRspecTestClass;end
end.to raise_error(RSpec::Mocks::MockExpectationError, "The message 'foo' was received by #{instance_two.inspect} but has already been received by #{instance_one.inspect}")
end
end
+
+ context "normal expectations on the class object" do
+ it "fail when unfulfilled" do
+ expect do
+ klass.any_instance.should_receive(:foo)
+ klass.should_receive(:woot)
+ klass.new.foo
+ klass.rspec_verify
+ end.to(raise_error(RSpec::Mocks::MockExpectationError) do |error|
+ error.message.should_not eq(existing_method_expectation_error_message)
+ end)
+ end
+
+
+ it "pass when expectations are met" do
+ klass.any_instance.should_receive(:foo)
+ klass.should_receive(:woot).and_return(result = Object.new)
+ klass.new.foo
+ klass.woot.should eq(result)
+ end
+ end
end
context "with an expectation is set on a method that exists" do
@@ -272,15 +293,6 @@ class RSpec::SampleRspecTestClass;end
end
end
- context "resetting" do
- it "does not interfere with expectations set on the class" do
- expect do
- klass.should_receive(:woot).and_return(3)
- klass.rspec_verify
- end.to raise_error(RSpec::Mocks::MockExpectationError)
- end
- end
-
context "message count" do
context "the 'once' constraint" do
it "passes for one invocation" do
Please sign in to comment.
Something went wrong with that request. Please try again.