1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 describe "TwiceCounts" do
7 @mock = mock("test mock")
10 it "twice should fail when call count is higher than expected" do
11 @mock.should_receive(:random_call).twice
17 end.should raise_error(MockExpectationError)
20 it "twice should fail when call count is lower than expected" do
21 @mock.should_receive(:random_call).twice
25 end.should raise_error(MockExpectationError)
28 it "twice should fail when called twice with wrong args on the first call" do
29 @mock.should_receive(:random_call).twice.with("1", 1)
31 @mock.random_call(1, "1")
32 end.should raise_error(MockExpectationError)
36 it "twice should fail when called twice with wrong args on the second call" do
37 @mock.should_receive(:random_call).twice.with("1", 1)
38 @mock.random_call("1", 1)
40 @mock.random_call(1, "1")
41 end.should raise_error(MockExpectationError)
45 it "twice should pass when called twice" do
46 @mock.should_receive(:random_call).twice
52 it "twice should pass when called twice with specified args" do
53 @mock.should_receive(:random_call).twice.with("1", 1)
54 @mock.random_call("1", 1)
55 @mock.random_call("1", 1)
59 it "twice should pass when called twice with unspecified args" do
60 @mock.should_receive(:random_call).twice
61 @mock.random_call("1")