Permalink
Browse files

Use `double` rather than `mock`/`stub`.

Since we've deprecated mock/stub as aliases for `double` in rspec-mocks.
  • Loading branch information...
1 parent 44d85eb commit 7194b33b3ffbc173c2b44bdbd5b83db84f88ea6c @myronmarston myronmarston committed Mar 4, 2013
View
4 spec/rspec/expectations/extensions/kernel_spec.rb
@@ -3,7 +3,7 @@
describe Object, "#should" do
before(:each) do
@target = "target"
- @matcher = mock("matcher")
+ @matcher = double("matcher")
@matcher.stub!(:matches?).and_return(true)
@matcher.stub!(:failure_message_for_should)
end
@@ -47,7 +47,7 @@ def method_missing(name, *args)
describe Object, "#should_not" do
before(:each) do
@target = "target"
- @matcher = mock("matcher")
+ @matcher = double("matcher")
end
it "accepts and interacts with a matcher" do
View
26 spec/rspec/expectations/handler_spec.rb
@@ -49,21 +49,21 @@ module Expectations
describe PositiveExpectationHandler do
describe "#handle_matcher" do
it "asks the matcher if it matches" do
- matcher = mock("matcher")
+ matcher = double("matcher")
actual = Object.new
matcher.should_receive(:matches?).with(actual).and_return(true)
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
end
it "returns the match value" do
- matcher = mock("matcher")
+ matcher = double("matcher")
actual = Object.new
matcher.should_receive(:matches?).with(actual).and_return(:this_value)
expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
end
it "calls failure_message_for_should if the matcher implements it" do
- matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false)
+ matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
actual = Object.new
::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -72,7 +72,7 @@ module Expectations
end
it "calls fail if matcher.diffable?" do
- matcher = mock("matcher",
+ matcher = double("matcher",
:diffable? => true,
:failure_message_for_should => "message",
:matches? => false,
@@ -87,7 +87,7 @@ module Expectations
end
it "calls failure_message if the matcher does not implement failure_message_for_should" do
- matcher = mock("matcher", :failure_message => "message", :matches? => false)
+ matcher = double("matcher", :failure_message => "message", :matches? => false)
actual = Object.new
::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -97,7 +97,7 @@ module Expectations
end
it "appends the :or message in the options hash passed to should" do
- matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false)
+ matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
actual = Object.new
::RSpec::Expectations.should_receive(:fail_with).with("custom")
@@ -110,22 +110,22 @@ module Expectations
describe NegativeExpectationHandler do
describe "#handle_matcher" do
it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
- matcher = mock("matcher", :does_not_match? => true, :negative_failure_message => nil)
+ matcher = double("matcher", :does_not_match? => true, :negative_failure_message => nil)
actual = Object.new
matcher.should_receive(:does_not_match?).with(actual).and_return(true)
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
end
it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
- matcher = mock("matcher")
+ matcher = double("matcher")
actual = Object.new
matcher.stub!(:negative_failure_message)
matcher.should_receive(:matches?).with(actual).and_return(false)
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
end
it "returns the match value" do
- matcher = mock("matcher")
+ matcher = double("matcher")
actual = Object.new
matcher.should_receive(:matches?).with(actual).and_return(false)
matcher.stub!(:negative_failure_message).and_return("ignore")
@@ -134,7 +134,7 @@ module Expectations
it "calls failure_message_for_should_not if the matcher implements it" do
- matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true)
+ matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
actual = Object.new
::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -144,7 +144,7 @@ module Expectations
end
it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do
- matcher = mock("matcher", :negative_failure_message => "message", :matches? => true)
+ matcher = double("matcher", :negative_failure_message => "message", :matches? => true)
actual = Object.new
::RSpec::Expectations.should_receive(:fail_with).with("message")
@@ -155,7 +155,7 @@ module Expectations
it "calls fail if matcher.diffable?" do
- matcher = mock("matcher",
+ matcher = double("matcher",
:diffable? => true,
:failure_message_for_should_not => "message",
:matches? => true,
@@ -170,7 +170,7 @@ module Expectations
end
it "appends the :or message in the options hash passed to should" do
- matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true)
+ matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
actual = Object.new
::RSpec::Expectations.should_receive(:fail_with).with("custom")
View
2 spec/rspec/matchers/be_close_spec.rb
@@ -8,7 +8,7 @@ module Matchers
end
it "delegates to be_within(delta).of(expected)" do
- should_receive(:be_within).with(0.5).and_return( be_within_matcher = stub )
+ should_receive(:be_within).with(0.5).and_return( be_within_matcher = double )
be_within_matcher.should_receive(:of).with(3.0)
be_close(3.0, 0.5)
end
View
64 spec/rspec/matchers/be_spec.rb
@@ -2,24 +2,24 @@
describe "expect(...).to be_predicate" do
it "passes when actual returns true for :predicate?" do
- actual = stub("actual", :happy? => true)
+ actual = double("actual", :happy? => true)
expect(actual).to be_happy
end
it "passes when actual returns true for :predicates? (present tense)" do
- actual = stub("actual", :exists? => true, :exist? => true)
+ actual = double("actual", :exists? => true, :exist? => true)
expect(actual).to be_exist
end
it "fails when actual returns false for :predicate?" do
- actual = stub("actual", :happy? => false)
+ actual = double("actual", :happy? => false)
expect {
expect(actual).to be_happy
}.to fail_with("expected happy? to return true, got false")
end
it "fails when actual returns false for :predicate?" do
- actual = stub("actual", :happy? => nil)
+ actual = double("actual", :happy? => nil)
expect {
expect(actual).to be_happy
}.to fail_with("expected happy? to return true, got nil")
@@ -32,7 +32,7 @@
end
it "fails on error other than NameError" do
- actual = stub("actual")
+ actual = double("actual")
actual.should_receive(:foo?).and_raise("aaaah")
expect {
expect(actual).to be_foo
@@ -50,17 +50,17 @@
describe "expect(...).not_to be_predicate" do
it "passes when actual returns false for :sym?" do
- actual = stub("actual", :happy? => false)
+ actual = double("actual", :happy? => false)
expect(actual).not_to be_happy
end
it "passes when actual returns nil for :sym?" do
- actual = stub("actual", :happy? => nil)
+ actual = double("actual", :happy? => nil)
expect(actual).not_to be_happy
end
it "fails when actual returns true for :sym?" do
- actual = stub("actual", :happy? => true)
+ actual = double("actual", :happy? => true)
expect {
expect(actual).not_to be_happy
}.to fail_with("expected happy? to return false, got true")
@@ -75,13 +75,13 @@
describe "expect(...).to be_predicate(*args)" do
it "passes when actual returns true for :predicate?(*args)" do
- actual = mock("actual")
+ actual = double("actual")
actual.should_receive(:older_than?).with(3).and_return(true)
expect(actual).to be_older_than(3)
end
it "fails when actual returns false for :predicate?(*args)" do
- actual = mock("actual")
+ actual = double("actual")
actual.should_receive(:older_than?).with(3).and_return(false)
expect {
expect(actual).to be_older_than(3)
@@ -97,13 +97,13 @@
describe "expect(...).not_to be_predicate(*args)" do
it "passes when actual returns false for :predicate?(*args)" do
- actual = mock("actual")
+ actual = double("actual")
actual.should_receive(:older_than?).with(3).and_return(false)
expect(actual).not_to be_older_than(3)
end
it "fails when actual returns true for :predicate?(*args)" do
- actual = mock("actual")
+ actual = double("actual")
actual.should_receive(:older_than?).with(3).and_return(true)
expect {
expect(actual).not_to be_older_than(3)
@@ -119,16 +119,16 @@
describe "expect(...).to be_predicate(&block)" do
it "passes when actual returns true for :predicate?(&block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:happy?).and_yield
delegate.should_receive(:check_happy).and_return(true)
expect(actual).to be_happy { delegate.check_happy }
end
it "fails when actual returns false for :predicate?(&block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:happy?).and_yield
delegate.should_receive(:check_happy).and_return(false)
expect {
@@ -137,7 +137,7 @@
end
it "fails when actual does not respond to :predicate?" do
- delegate = mock("delegate", :check_happy => true)
+ delegate = double("delegate", :check_happy => true)
expect {
expect(Object.new).to be_happy { delegate.check_happy }
}.to raise_error(NameError)
@@ -146,16 +146,16 @@
describe "expect(...).not_to be_predicate(&block)" do
it "passes when actual returns false for :predicate?(&block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:happy?).and_yield
delegate.should_receive(:check_happy).and_return(false)
expect(actual).not_to be_happy { delegate.check_happy }
end
it "fails when actual returns true for :predicate?(&block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:happy?).and_yield
delegate.should_receive(:check_happy).and_return(true)
expect {
@@ -164,7 +164,7 @@
end
it "fails when actual does not respond to :predicate?" do
- delegate = mock("delegate", :check_happy => true)
+ delegate = double("delegate", :check_happy => true)
expect {
expect(Object.new).not_to be_happy { delegate.check_happy }
}.to raise_error(NameError)
@@ -173,16 +173,16 @@
describe "expect(...).to be_predicate(*args, &block)" do
it "passes when actual returns true for :predicate?(*args, &block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:older_than?).with(3).and_yield(3)
delegate.should_receive(:check_older_than).with(3).and_return(true)
expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
end
it "fails when actual returns false for :predicate?(*args, &block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:older_than?).with(3).and_yield(3)
delegate.should_receive(:check_older_than).with(3).and_return(false)
expect {
@@ -191,7 +191,7 @@
end
it "fails when actual does not respond to :predicate?" do
- delegate = mock("delegate", :check_older_than => true)
+ delegate = double("delegate", :check_older_than => true)
expect {
expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) }
}.to raise_error(NameError)
@@ -200,16 +200,16 @@
describe "expect(...).not_to be_predicate(*args, &block)" do
it "passes when actual returns false for :predicate?(*args, &block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:older_than?).with(3).and_yield(3)
delegate.should_receive(:check_older_than).with(3).and_return(false)
expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
end
it "fails when actual returns true for :predicate?(*args, &block)" do
- actual = mock("actual")
- delegate = mock("delegate")
+ actual = double("actual")
+ delegate = double("delegate")
actual.should_receive(:older_than?).with(3).and_yield(3)
delegate.should_receive(:check_older_than).with(3).and_return(true)
expect {
@@ -218,7 +218,7 @@
end
it "fails when actual does not respond to :predicate?" do
- delegate = mock("delegate", :check_older_than => true)
+ delegate = double("delegate", :check_older_than => true)
expect {
expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
}.to raise_error(NameError)
View
2 spec/rspec/matchers/configuration_spec.rb
@@ -36,7 +36,7 @@ module Matchers
end
it "can be set to another backtrace formatter" do
- config.backtrace_formatter = stub(:format_backtrace => ['a'])
+ config.backtrace_formatter = double(:format_backtrace => ['a'])
expect(formatted_backtrace).to eq(['a'])
end
end
View
18 spec/rspec/matchers/exist_spec.rb
@@ -8,7 +8,7 @@
end
context "when the object does not respond to #exist? or #exists?" do
- subject { mock }
+ subject { double }
[:to, :not_to].each do |expect_method|
describe "expect(...).#{expect_method} exist" do
@@ -25,12 +25,12 @@
context "when the object responds to ##{predicate}" do
describe "expect(...).to exist" do
it "passes if #{predicate}" do
- expect(mock(predicate => true)).to exist
+ expect(double(predicate => true)).to exist
end
it "fails if not #{predicate}" do
expect {
- expect(mock(predicate => false)).to exist
+ expect(double(predicate => false)).to exist
}.to fail_with(/expected .* to exist/)
end
@@ -51,12 +51,12 @@ def send
describe "expect(...).not_to exist" do
it "passes if not #{predicate}" do
- expect(mock(predicate => false)).not_to exist
+ expect(double(predicate => false)).not_to exist
end
it "fails if #{predicate}" do
expect {
- expect(mock(predicate => true)).not_to exist
+ expect(double(predicate => true)).not_to exist
}.to fail_with(/expected .* not to exist/)
end
end
@@ -65,7 +65,7 @@ def send
context "when the object responds to #exist? and #exists?" do
context "when they both return falsey values" do
- subject { mock(:exist? => false, :exists? => nil) }
+ subject { double(:exist? => false, :exists? => nil) }
describe "expect(...).not_to exist" do
it "passes" do
@@ -83,7 +83,7 @@ def send
end
context "when they both return truthy values" do
- subject { mock(:exist? => true, :exists? => "something true") }
+ subject { double(:exist? => true, :exists? => "something true") }
describe "expect(...).not_to exist" do
it "fails" do
@@ -101,7 +101,7 @@ def send
end
context "when they return values with different truthiness" do
- subject { mock(:exist? => true, :exists? => false) }
+ subject { double(:exist? => true, :exists? => false) }
[:to, :not_to].each do |expect_method|
describe "expect(...).#{expect_method} exist" do
@@ -116,7 +116,7 @@ def send
end
it 'passes any provided arguments to the call to #exist?' do
- object = mock
+ object = double
object.should_receive(:exist?).with(:foo, :bar) { true }
expect(object).to exist(:foo, :bar)
View
4 spec/rspec/matchers/have_spec.rb
@@ -326,13 +326,13 @@ def items
describe "have(n).items(args, block)" do
it "passes args to target" do
- target = mock("target")
+ target = double("target")
target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
expect(target).to have(3).items("arg1","arg2")
end
it "passes block to target" do
- target = mock("target")
+ target = double("target")
block = lambda { 5 }
target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
expect(target).to have(3).items("arg1","arg2", block)
View
4 spec/rspec/matchers/include_matcher_integration_spec.rb
@@ -22,8 +22,8 @@ class NotHashSubclass; end
end
it "works with be_[some predicate]" do
- expect([stub("actual", :happy? => true)]).to include( be_happy )
- expect([stub("actual", :happy? => false)]).not_to include( be_happy )
+ expect([double("actual", :happy? => true)]).to include( be_happy )
+ expect([double("actual", :happy? => false)]).not_to include( be_happy )
end
end
end

0 comments on commit 7194b33

Please sign in to comment.