spec/rspec/mocks/any_instance_spec.rb in rspec-mocks-2.11.2 vs spec/rspec/mocks/any_instance_spec.rb in rspec-mocks-2.11.3
- old
+ new
@@ -843,8 +843,35 @@
instance_one.existing_method
instance_two.existing_method
end.to raise_error(RSpec::Mocks::MockExpectationError, "The message 'existing_method' was received by #{instance_two.inspect} but has already been received by #{instance_one.inspect}")
end
end
+
+ context "when a class overrides Object#method" do
+ let(:http_request_class) { Struct.new(:method, :uri) }
+
+ it "stubs the method correctly" do
+ http_request_class.any_instance.stub(:existing_method).and_return("foo")
+ http_request_class.new.existing_method.should == "foo"
+ end
+
+ it "mocks the method correctly" do
+ http_request_class.any_instance.should_receive(:existing_method).and_return("foo")
+ http_request_class.new.existing_method.should == "foo"
+ end
+ end
+
+ context "when used after the test has finished" do
+ it "restores the original behavior of a stubbed method" do
+ klass.any_instance.stub(:existing_method).and_return(:stubbed_return_value)
+
+ instance = klass.new
+ instance.existing_method.should == :stubbed_return_value
+
+ RSpec::Mocks.verify
+
+ instance.existing_method.should == :existing_method_return_value
+ end
+ end
end
end
end