Skip to content

Commit

Permalink
double down
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Mar 17, 2010
1 parent a6a25f4 commit 650cd24
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 137 deletions.
2 changes: 1 addition & 1 deletion features/mocks/mix_stubs_and_mocks.feature
Expand Up @@ -14,7 +14,7 @@ Feature: Spec and test together
describe "a stub in before" do
before(:each) do
@messenger = mock('messenger').as_null_object
@messenger = double('messenger').as_null_object
end
it "a" do
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/mocks.rb
Expand Up @@ -68,13 +68,13 @@ module Rspec
#
# You can create a mock in any specification (or setup) using:
#
# mock(name, options={})
# double(name, options={})
#
# The optional +options+ argument is a +Hash+. Currently the only supported
# option is +:null_object+. Setting this to true instructs the mock to ignore
# any messages it hasn’t been told to expect – and quietly return itself. For example:
#
# mock("person", :null_object => true)
# double("person", :null_object => true)
#
# == Creating a Stub
#
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/mocks/argument_matchers.rb
Expand Up @@ -172,7 +172,7 @@ def no_args
# == Examples
#
# array = []
# display = mock('display')
# display = double('display')
# display.should_receive(:present_names).with(duck_type(:length, :each))
# => passes
def duck_type(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/mocks/spec_methods.rb
Expand Up @@ -14,7 +14,7 @@ module ExampleMethods
#
# == Examples
#
# stub_thing = mock("thing", :a => "A")
# stub_thing = double("thing", :a => "A")
# stub_thing.a == "A" => true
#
# stub_person = stub("thing", :name => "Joe", :email => "joe@domain.com")
Expand Down
4 changes: 2 additions & 2 deletions spec/rspec/mocks/argument_expectation_spec.rb
Expand Up @@ -5,15 +5,15 @@ module Mocks
describe ArgumentExpectation do
it "should consider an object that responds to #matches? and #description to be a matcher" do
argument_expecatation = Rspec::Mocks::ArgumentExpectation.new([])
obj = mock("matcher")
obj = double("matcher")
obj.should_receive(:respond_to?).with(:matches?).and_return(true)
obj.should_receive(:respond_to?).with(:description).and_return(true)
argument_expecatation.is_matcher?(obj).should be_true
end

it "should NOT consider an object that only responds to #matches? to be a matcher" do
argument_expecatation = Rspec::Mocks::ArgumentExpectation.new([])
obj = mock("matcher")
obj = double("matcher")
obj.should_receive(:respond_to?).with(:matches?).and_return(true)
obj.should_receive(:respond_to?).with(:description).and_return(false)
argument_expecatation.is_matcher?(obj).should be_false
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/mocks/bug_report_10260_spec.rb
Expand Up @@ -2,7 +2,7 @@

describe "An RSpec Mock" do
it "should hide internals in its inspect representation" do
m = mock('cup')
m = double('cup')
m.inspect.should =~ /#<Rspec::Mocks::Mock:0x[a-f0-9.]+ @name="cup">/
end
end
16 changes: 8 additions & 8 deletions spec/rspec/mocks/bug_report_10263_spec.rb
@@ -1,26 +1,26 @@
describe "Mock" do
before do
@mock = mock("test mock")
@double = double("test double")
end

specify "when one example has an expectation (non-mock) inside the block passed to the mock" do
@mock.should_receive(:msg) do |b|
@double.should_receive(:msg) do |b|
b.should be_true #this call exposes the problem
end
begin
@mock.msg(false)
@double.msg(false)
rescue Exception
end
end

specify "then the next example should behave as expected instead of saying" do
@mock.should_receive(:foobar)
@mock.foobar
@mock.rspec_verify
@double.should_receive(:foobar)
@double.foobar
@double.rspec_verify
begin
@mock.foobar
@double.foobar
rescue Exception => e
e.message.should == "Mock \"test mock\" received unexpected message :foobar with (no args)"
e.message.should == "Double \"test double\" received unexpected message :foobar with (no args)"
end
end
end
Expand Down
22 changes: 11 additions & 11 deletions spec/rspec/mocks/bug_report_15719_spec.rb
Expand Up @@ -5,24 +5,24 @@ module Mocks
describe "mock failure" do

it "should tell you when it receives the right message with the wrong args" do
m = mock("foo")
m.should_receive(:bar).with("message")
double = double("foo")
double.should_receive(:bar).with("message")
lambda {
m.bar("different message")
}.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Mock "foo" received :bar with unexpected arguments\n expected: ("message")\n got: ("different message")})
m.rspec_reset # so the example doesn't fail
double.bar("different message")
}.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Double "foo" received :bar with unexpected arguments\n expected: ("message")\n got: ("different message")})
double.rspec_reset # so the example doesn't fail
end

pending "should tell you when it receives the right message with the wrong args if you stub the method (fix bug 15719)" do
# NOTE - for whatever reason, if you use a the block style of pending here,
# rcov gets unhappy. Don't know why yet.
m = mock("foo")
m.stub(:bar)
m.should_receive(:bar).with("message")
double = double("foo")
double.stub(:bar)
double.should_receive(:bar).with("message")
lambda {
m.bar("different message")
}.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")})
m.rspec_reset # so the example doesn't fail
double.bar("different message")
}.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Double 'foo' expected :bar with ("message") but received it with ("different message")})
double.rspec_reset # so the example doesn't fail
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/mocks/bug_report_8165_spec.rb
Expand Up @@ -21,7 +21,7 @@
end

it "should not raise an exception for mock" do
obj = mock("obj")
obj = double("obj")
obj.should_receive(:respond_to?).with(:foobar).and_return(true)
obj.should_receive(:foobar).and_return(:baz)
obj.respond_to?(:foobar).should be_true
Expand Down
12 changes: 6 additions & 6 deletions spec/rspec/mocks/failing_argument_matchers_spec.rb
Expand Up @@ -4,7 +4,7 @@ module Rspec
module Mocks
describe "failing MockArgumentMatchers" do
before(:each) do
@mock = mock("test mock")
@mock = double("test double")
@reporter = Rspec::Mocks::Mock.new("reporter", :null_object => true)
end

Expand Down Expand Up @@ -52,35 +52,35 @@ module Mocks
@mock.should_receive(:random_call).with(:a => "b", :c => "d")
lambda do
@mock.random_call(:a => "b", :c => "e")
end.should raise_error(Rspec::Mocks::MockExpectationError, /Mock "test mock" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
end.should raise_error(Rspec::Mocks::MockExpectationError, /Double "test double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
end

it "should fail for a hash w/ wrong keys" do
@mock.should_receive(:random_call).with(:a => "b", :c => "d")
lambda do
@mock.random_call("a" => "b", "c" => "d")
end.should raise_error(Rspec::Mocks::MockExpectationError, /Mock "test mock" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
end.should raise_error(Rspec::Mocks::MockExpectationError, /Double "test double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
end

it "should match against a Matcher" do
lambda do
@mock.should_receive(:msg).with(equal(3))
@mock.msg(37)
end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock \"test mock\" received :msg with unexpected arguments\n expected: (equal 3)\n got: (37)")
end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (equal 3)\n got: (37)")
end

it "should fail no_args with one arg" do
lambda do
@mock.should_receive(:msg).with(no_args)
@mock.msg(37)
end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock \"test mock\" received :msg with unexpected arguments\n expected: (no args)\n got: (37)")
end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (no args)\n got: (37)")
end

it "should fail hash_including with missing key" do
lambda do
@mock.should_receive(:msg).with(hash_including(:a => 1))
@mock.msg({})
end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock \"test mock\" received :msg with unexpected arguments\n expected: (hash_including(:a=>1))\n got: ({})")
end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (hash_including(:a=>1))\n got: ({})")
end

it "should fail with block matchers" do
Expand Down
108 changes: 54 additions & 54 deletions spec/rspec/mocks/mock_ordering_spec.rb
Expand Up @@ -3,90 +3,90 @@
module Rspec
module Mocks

describe "Mock ordering" do
describe "ordering" do

before do
@mock = mock("test mock")
@double = double("test double")
end

after do
@mock.rspec_reset
@double.rspec_reset
end

it "should pass two calls in order" do
@mock.should_receive(:one).ordered
@mock.should_receive(:two).ordered
@mock.one
@mock.two
@mock.rspec_verify
@double.should_receive(:one).ordered
@double.should_receive(:two).ordered
@double.one
@double.two
@double.rspec_verify
end

it "should pass three calls in order" do
@mock.should_receive(:one).ordered
@mock.should_receive(:two).ordered
@mock.should_receive(:three).ordered
@mock.one
@mock.two
@mock.three
@mock.rspec_verify
@double.should_receive(:one).ordered
@double.should_receive(:two).ordered
@double.should_receive(:three).ordered
@double.one
@double.two
@double.three
@double.rspec_verify
end

it "should fail if second call comes first" do
@mock.should_receive(:one).ordered
@mock.should_receive(:two).ordered
@double.should_receive(:one).ordered
@double.should_receive(:two).ordered
lambda do
@mock.two
end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock \"test mock\" received :two out of order")
@double.two
end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :two out of order")
end

it "should fail if third call comes first" do
@mock.should_receive(:one).ordered
@mock.should_receive(:two).ordered
@mock.should_receive(:three).ordered
@mock.one
@double.should_receive(:one).ordered
@double.should_receive(:two).ordered
@double.should_receive(:three).ordered
@double.one
lambda do
@mock.three
end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock \"test mock\" received :three out of order")
@double.three
end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
end

it "should fail if third call comes second" do
@mock.should_receive(:one).ordered
@mock.should_receive(:two).ordered
@mock.should_receive(:three).ordered
@mock.one
@double.should_receive(:one).ordered
@double.should_receive(:two).ordered
@double.should_receive(:three).ordered
@double.one
lambda do
@mock.three
end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock \"test mock\" received :three out of order")
@double.three
end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
end

it "should ignore order of non ordered calls" do
@mock.should_receive(:ignored_0)
@mock.should_receive(:ordered_1).ordered
@mock.should_receive(:ignored_1)
@mock.should_receive(:ordered_2).ordered
@mock.should_receive(:ignored_2)
@mock.should_receive(:ignored_3)
@mock.should_receive(:ordered_3).ordered
@mock.should_receive(:ignored_4)
@mock.ignored_3
@mock.ordered_1
@mock.ignored_0
@mock.ordered_2
@mock.ignored_4
@mock.ignored_2
@mock.ordered_3
@mock.ignored_1
@mock.rspec_verify
@double.should_receive(:ignored_0)
@double.should_receive(:ordered_1).ordered
@double.should_receive(:ignored_1)
@double.should_receive(:ordered_2).ordered
@double.should_receive(:ignored_2)
@double.should_receive(:ignored_3)
@double.should_receive(:ordered_3).ordered
@double.should_receive(:ignored_4)
@double.ignored_3
@double.ordered_1
@double.ignored_0
@double.ordered_2
@double.ignored_4
@double.ignored_2
@double.ordered_3
@double.ignored_1
@double.rspec_verify
end

it "should pass when duplicates exist" do
@mock.should_receive(:a).ordered
@mock.should_receive(:b).ordered
@mock.should_receive(:a).ordered
@double.should_receive(:a).ordered
@double.should_receive(:b).ordered
@double.should_receive(:a).ordered

@mock.a
@mock.b
@mock.a
@double.a
@double.b
@double.a
end

end
Expand Down
8 changes: 4 additions & 4 deletions spec/rspec/mocks/mock_space_spec.rb
Expand Up @@ -31,19 +31,19 @@ def reset?
@m2.should be_verified
end
it "should reset all mocks within" do
@space.add(m1 = mock("mock1"))
@space.add(m2 = mock("mock2"))
@space.add(m1 = double("mock1"))
@space.add(m2 = double("mock2"))
m1.should_receive(:rspec_reset)
m2.should_receive(:rspec_reset)
@space.reset_all
end
it "should clear internal mocks on reset_all" do
@space.add(m = mock("mock"))
@space.add(m = double("mock"))
@space.reset_all
@space.instance_eval { mocks.empty? }.should be_true
end
it "should only add an instance once" do
@space.add(m1 = mock("mock1"))
@space.add(m1 = double("mock1"))
@space.add(m1)
m1.should_receive(:rspec_verify)
@space.verify_all
Expand Down

0 comments on commit 650cd24

Please sign in to comment.