1 require File.dirname(__FILE__) + '/../../spec_helper'
5 describe "a Mock expectation with multiple return values and no specified count" do
7 @mock = Mock.new("mock")
8 @return_values = ["1",2,Object.new]
9 @mock.should_receive(:message).and_return(@return_values[0],@return_values[1],@return_values[2])
12 it "should return values in order to consecutive calls" do
13 @mock.message.should == @return_values[0]
14 @mock.message.should == @return_values[1]
15 @mock.message.should == @return_values[2]
19 it "should complain when there are too few calls" do
21 @mock.message.should == @return_values[0]
22 @mock.message.should == @return_values[1]
23 lambda { @mock.rspec_verify }.should raise_error(MockExpectationError, "Mock 'mock' expected :message with (any args) 3 times, but received it twice")
26 it "should complain when there are too many calls" do
28 @mock.message.should == @return_values[0]
29 @mock.message.should == @return_values[1]
30 @mock.message.should == @return_values[2]
31 @mock.message.should == @return_values[2]
32 lambda { @mock.rspec_verify }.should raise_error(MockExpectationError, "Mock 'mock' expected :message with (any args) 3 times, but received it 4 times")
36 describe "a Mock expectation with multiple return values with a specified count equal to the number of values" do
38 @mock = Mock.new("mock")
39 @return_values = ["1",2,Object.new]
40 @mock.should_receive(:message).exactly(3).times.and_return(@return_values[0],@return_values[1],@return_values[2])
43 it "should return values in order to consecutive calls" do
44 @mock.message.should == @return_values[0]
45 @mock.message.should == @return_values[1]
46 @mock.message.should == @return_values[2]
50 it "should complain when there are too few calls" do
52 @mock.message.should == @return_values[0]
53 @mock.message.should == @return_values[1]
54 lambda { @mock.rspec_verify }.should raise_error(MockExpectationError, "Mock 'mock' expected :message with (any args) 3 times, but received it twice")
57 it "should complain when there are too many calls" do
59 @mock.message.should == @return_values[0]
60 @mock.message.should == @return_values[1]
61 @mock.message.should == @return_values[2]
62 @mock.message.should == @return_values[2]
63 lambda { @mock.rspec_verify }.should raise_error(MockExpectationError, "Mock 'mock' expected :message with (any args) 3 times, but received it 4 times")
67 describe "a Mock expectation with multiple return values specifying at_least less than the number of values" do
69 @mock = Mock.new("mock")
70 @mock.should_receive(:message).at_least(:twice).with(no_args).and_return(11, 22)
73 it "should use last return value for subsequent calls" do
74 @mock.message.should equal(11)
75 @mock.message.should equal(22)
76 @mock.message.should equal(22)
80 it "should fail when called less than the specified number" do
81 @mock.message.should equal(11)
82 lambda { @mock.rspec_verify }.should raise_error(MockExpectationError, "Mock 'mock' expected :message with (no args) twice, but received it once")
85 describe "a Mock expectation with multiple return values with a specified count larger than the number of values" do
87 @mock = Mock.new("mock")
88 @mock.should_receive(:message).exactly(3).times.and_return(11, 22)
91 it "should use last return value for subsequent calls" do
92 @mock.message.should equal(11)
93 @mock.message.should equal(22)
94 @mock.message.should equal(22)
98 it "should fail when called less than the specified number" do
99 @mock.message.should equal(11)
100 lambda { @mock.rspec_verify }.should raise_error(MockExpectationError, "Mock 'mock' expected :message with (any args) 3 times, but received it once")
103 it "should fail when called greater than the specified number" do
104 @mock.message.should equal(11)
105 @mock.message.should equal(22)
106 @mock.message.should equal(22)
107 @mock.message.should equal(22)
108 lambda { @mock.rspec_verify }.should raise_error(MockExpectationError, "Mock 'mock' expected :message with (any args) 3 times, but received it 4 times")