Skip to content

Commit

Permalink
Merge pull request #233 from michihuber/deprecate_stub_mock
Browse files Browse the repository at this point in the history
Deprecate stub mock
  • Loading branch information
myronmarston committed Mar 1, 2013
2 parents 90f10df + 843a40f commit e7e72dd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/rspec/mocks/example_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ def double(*args)
declare_double('Double', *args)
end

# Effectively an alias for [double](#double-instance_method).
# Deprecated: Use [double](#double-instance_method).
def mock(*args)
RSpec::Mocks.warn_deprecation "\nDEPRECATION: use #double instead of #mock. #{caller(0)[1]}\n"
declare_double('Mock', *args)
end

# Effectively an alias for [double](#double-instance_method).
# Deprecated: Use [double](#double-instance_method).
def stub(*args)
RSpec::Mocks.warn_deprecation "\nDEPRECATION: use #double instead of #stub. #{caller(0)[1]}\n"
declare_double('Stub', *args)
end

Expand Down
14 changes: 13 additions & 1 deletion spec/rspec/mocks/double_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
it "is an alias for stub and mock" do
expect(double()).to be_a(RSpec::Mocks::Mock)
end

it "uses 'Double' in failure messages" do
double = double('name')
expect {double.foo}.to raise_error(/Double "name" received/)
end

describe "deprecated aliases" do
it "warns if #stub is used" do
RSpec::Mocks.should_receive(:warn_deprecation).with(/DEPRECATION: use #double instead of #stub/)
stub("TestDouble")
end

it "warns if #mock is used" do
RSpec::Mocks.should_receive(:warn_deprecation).with(/DEPRECATION: use #double instead of #mock/)
mock("TestDouble")
end
end
end
2 changes: 1 addition & 1 deletion spec/rspec/mocks/partial_mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def method_missing(*a)

describe "Partially mocking an object that defines ==, after another mock has been defined" do
before(:each) do
stub("existing mock", :foo => :foo)
double("existing mock", :foo => :foo)
end

let(:klass) do
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/mocks/stub_implementation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ module Mocks
describe "stub implementation" do
describe "with no args" do
it "execs the block when called" do
obj = stub()
obj = double()
obj.stub(:foo) { :bar }
expect(obj.foo).to eq :bar
end
end

describe "with one arg" do
it "execs the block with that arg when called" do
obj = stub()
obj = double()
obj.stub(:foo) {|given| given}
expect(obj.foo(:bar)).to eq :bar
end
end

describe "with variable args" do
it "execs the block when called" do
obj = stub()
obj = double()
obj.stub(:foo) {|*given| given.first}
expect(obj.foo(:bar)).to eq :bar
end
Expand Down

0 comments on commit e7e72dd

Please sign in to comment.