From a283324559d2b67abb1c9d741371c7922af1c36d Mon Sep 17 00:00:00 2001 From: Ryan Jones Date: Thu, 7 Feb 2013 10:11:51 -0700 Subject: [PATCH] disallow unstub! on any_instance --- lib/rspec/mocks/any_instance/recorder.rb | 5 +++++ spec/rspec/mocks/any_instance_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/rspec/mocks/any_instance/recorder.rb b/lib/rspec/mocks/any_instance/recorder.rb index f117598e5..fd7961b12 100644 --- a/lib/rspec/mocks/any_instance/recorder.rb +++ b/lib/rspec/mocks/any_instance/recorder.rb @@ -91,6 +91,11 @@ def stub!(*) raise "stub! is not supported on any_instance. Use stub instead." end + # @private + def unstub!(*) + raise "unstub! is not supported on any_instance. Use unstub instead." + end + # @private def stop_all_observation! @observed_methods.each {|method_name| restore_method!(method_name)} diff --git a/spec/rspec/mocks/any_instance_spec.rb b/spec/rspec/mocks/any_instance_spec.rb index 459916090..195ac7897 100644 --- a/spec/rspec/mocks/any_instance_spec.rb +++ b/spec/rspec/mocks/any_instance_spec.rb @@ -245,6 +245,14 @@ class RSpec::SampleRspecTestClass;end end end + context "with #unstub!" do + it "raises with a message instructing the user to use unstub instead" do + expect do + klass.any_instance.unstub!(:foo) + end.to raise_error(/Use unstub instead/) + end + end + context "unstub implementation" do it "replaces the stubbed method with the original method" do klass.any_instance.stub(:existing_method)