Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate stub mock #233

Merged
merged 2 commits into from
Mar 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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