Skip to content

Commit

Permalink
Remove stub! and unstub!.
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information
Sam Phippen committed Jul 4, 2013
1 parent 6ef6f11 commit d4daf14
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 65 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -5,6 +5,7 @@ Breaking Changes for 3.0.0:
* Raise an explicit error if `should_not_receive(...).and_return` is used. (Sam
Phippen)
* Remove 1.8.6 workarounds (Jon Rowe)
* Remove `stub!` and `unstub!`. (Sam Phippen)

Enhancements:

Expand Down
10 changes: 0 additions & 10 deletions lib/rspec/mocks/any_instance/recorder.rb
Expand Up @@ -88,16 +88,6 @@ def verify
::RSpec::Mocks.space.remove_any_instance_recorder_for(@klass)
end

# @private
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
12 changes: 0 additions & 12 deletions lib/rspec/mocks/syntax.rb
Expand Up @@ -34,16 +34,6 @@ def unstub(message)
::RSpec::Mocks.space.proxy_for(self).remove_stub(message)
end

def stub!(message_or_hash, opts={}, &block)
::RSpec.deprecate "stub!", :replacement => "stub"
stub(message_or_hash, opts={}, &block)
end

def unstub!(message)
::RSpec.deprecate "unstub!", :replacement => "unstub"
unstub(message)
end

def stub_chain(*chain, &blk)
::RSpec::Mocks::StubChain.stub_chain_on(self, *chain, &blk)
end
Expand Down Expand Up @@ -81,8 +71,6 @@ def self.disable_should(syntax_host = default_should_syntax_host)
undef should_not_receive
undef stub
undef unstub
undef stub!
undef unstub!
undef stub_chain
undef as_null_object
undef null_object?
Expand Down
16 changes: 0 additions & 16 deletions spec/rspec/mocks/any_instance_spec.rb
Expand Up @@ -265,22 +265,6 @@ class RSpec::SampleRspecTestClass;end
end
end

context "with #stub!" do
it "raises with a message instructing the user to use stub instead" do
expect do
klass.any_instance.stub!(:foo)
end.to raise_error(/Use stub instead/)
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
2 changes: 1 addition & 1 deletion spec/rspec/mocks/methods_spec.rb
Expand Up @@ -18,7 +18,7 @@ def added_methods
expect(added_methods).to match_array([
:as_null_object, :null_object?,
:received_message?, :should_not_receive, :should_receive,
:stub, :stub!, :stub_chain, :unstub, :unstub!
:stub, :stub_chain, :unstub
])
end
end
Expand Down
26 changes: 0 additions & 26 deletions spec/rspec/mocks/stub_spec.rb
Expand Up @@ -37,32 +37,6 @@ def existing_private_instance_method
end
end

describe "using stub!" do
it "warns of deprecation but still returns the declared value when message is received" do
expect(RSpec).to receive(:deprecate).with("stub!", :replacement => "stub")
@instance.stub!(:msg).and_return(:return_value)
expect(@instance.msg).to equal(:return_value)
verify @instance
end
end

describe 'using unstub' do
it 'removes the message stub' do
@instance.stub(:msg)
@instance.unstub(:msg)
expect { @instance.msg }.to raise_error NoMethodError
end
end

describe 'using unstub!' do
it 'removes the message stub but warns about deprecation' do
@instance.stub(:msg)
RSpec.should_receive(:deprecate).with("unstub!", :replacement => "unstub")
@instance.unstub!(:msg)
expect { @instance.msg }.to raise_error NoMethodError
end
end

it "instructs an instance to respond_to the message" do
@instance.stub(:msg)
expect(@instance).to respond_to(:msg)
Expand Down

0 comments on commit d4daf14

Please sign in to comment.