1
require File.dirname(__FILE__) + '/../../spec_helper.rb'
5
describe "using a Partial Mock," do
10
it "should name the class in the failure message" do
11
@object.should_receive(:foo)
14
end.should raise_error(Spec::Mocks::MockExpectationError, /Object/)
17
it "should not conflict with @options in the object" do
18
@object.instance_eval { @options = Object.new }
19
@object.should_receive(:blah)
23
it "should_not_receive should mock out the method" do
24
@object.should_not_receive(:fuhbar)
28
end.should raise_error(Spec::Mocks::MockExpectationError)
31
it "should_not_receive should return a negative message expectation" do
32
@object.should_not_receive(:foobar).should be_kind_of(NegativeMessageExpectation)
35
it "should_receive should mock out the method" do
36
@object.should_receive(:foobar).with(:test_param).and_return(1)
37
@object.foobar(:test_param).should equal(1)
40
it "should_receive should handle a hash" do
41
@object.should_receive(:foobar).with(:key => "value").and_return(1)
42
@object.foobar(:key => "value").should equal(1)
45
it "should_receive should handle an inner hash" do
46
hash = {:a => {:key => "value"}}
47
@object.should_receive(:foobar).with(:key => "value").and_return(1)
48
@object.foobar(hash[:a]).should equal(1)
51
it "should_receive should return a message expectation" do
52
@object.should_receive(:foobar).should be_kind_of(MessageExpectation)
56
it "should_receive should verify method was called" do
57
@object.should_receive(:foobar).with(:test_param).and_return(1)
60
end.should raise_error(Spec::Mocks::MockExpectationError)
63
it "should_receive should also take a String argument" do
64
@object.should_receive('foobar')
68
it "should_not_receive should also take a String argument" do
69
@object.should_not_receive('foobar')
73
end.should raise_error(Spec::Mocks::MockExpectationError)
76
it "should use report nil in the error message" do
77
@this_will_resolve_to_nil.should_receive(:foobar)
79
@this_will_resolve_to_nil.rspec_verify
80
end.should raise_error(Spec::Mocks::MockExpectationError, /NilClass.*expected :foobar with/)
84
describe "Partially mocking an object that defines ==, after another mock has been defined" do
86
stub("existing mock", :foo => :foo)
89
class PartiallyMockedEquals
100
it "should not raise an error when stubbing the object" do
101
o = PartiallyMockedEquals.new :foo
102
lambda { o.stub!(:bar) }.should_not raise_error(NoMethodError)