]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/mocks/twice_counts_spec.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / mocks / twice_counts_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3 module Spec
4   module Mocks
5     describe "TwiceCounts" do
6       before(:each) do
7         @mock = mock("test mock")
8       end
9
10       it "twice should fail when call count is higher than expected" do
11         @mock.should_receive(:random_call).twice
12         @mock.random_call
13         @mock.random_call
14         @mock.random_call
15         lambda do
16           @mock.rspec_verify
17         end.should raise_error(MockExpectationError)
18       end
19       
20       it "twice should fail when call count is lower than expected" do
21         @mock.should_receive(:random_call).twice
22         @mock.random_call
23         lambda do
24           @mock.rspec_verify
25         end.should raise_error(MockExpectationError)
26       end
27       
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)
30         lambda do
31           @mock.random_call(1, "1")
32         end.should raise_error(MockExpectationError)
33         @mock.rspec_reset
34       end
35       
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)
39         lambda do
40           @mock.random_call(1, "1")
41         end.should raise_error(MockExpectationError)
42         @mock.rspec_reset
43       end
44       
45       it "twice should pass when called twice" do
46         @mock.should_receive(:random_call).twice
47         @mock.random_call
48         @mock.random_call
49         @mock.rspec_verify
50       end
51       
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)
56         @mock.rspec_verify
57       end
58       
59       it "twice should pass when called twice with unspecified args" do
60         @mock.should_receive(:random_call).twice
61         @mock.random_call("1")
62         @mock.random_call(1)
63         @mock.rspec_verify
64       end
65     end
66   end
67 end