Skip to content

Commit

Permalink
disallow unstub! on any_instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Jones committed Feb 7, 2013
1 parent c454058 commit a283324
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rspec/mocks/any_instance/recorder.rb
Expand Up @@ -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)}
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/mocks/any_instance_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit a283324

Please sign in to comment.