changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/mocks/at_most_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3module Spec
4 module Mocks
5 describe "at_most" do
6 before(:each) do
7 @mock = Mock.new("test mock")
8 end
9
10 it "should fail when at most n times method is called n plus 1 times" do
11 @mock.should_receive(:random_call).at_most(4).times
12 @mock.random_call
13 @mock.random_call
14 @mock.random_call
15 @mock.random_call
16 @mock.random_call
17 lambda do
18 @mock.rspec_verify
19 end.should raise_error(MockExpectationError)
20 end
21
22 it "should fail when at most once method is called twice" do
23 @mock.should_receive(:random_call).at_most(:once)
24 @mock.random_call
25 @mock.random_call
26 lambda do
27 @mock.rspec_verify
28 end.should raise_error(MockExpectationError)
29 end
30
31 it "should fail when at most twice method is called three times" do
32 @mock.should_receive(:random_call).at_most(:twice)
33 @mock.random_call
34 @mock.random_call
35 @mock.random_call
36 lambda do
37 @mock.rspec_verify
38 end.should raise_error(MockExpectationError)
39 end
40
41 it "should pass when at most n times method is called exactly n times" do
42 @mock.should_receive(:random_call).at_most(4).times
43 @mock.random_call
44 @mock.random_call
45 @mock.random_call
46 @mock.random_call
47 @mock.rspec_verify
48 end
49
50 it "should pass when at most n times method is called less than n times" do
51 @mock.should_receive(:random_call).at_most(4).times
52 @mock.random_call
53 @mock.random_call
54 @mock.random_call
55 @mock.rspec_verify
56 end
57
58 it "should pass when at most n times method is never called" do
59 @mock.should_receive(:random_call).at_most(4).times
60 @mock.rspec_verify
61 end
62
63 it "should pass when at most once method is called once" do
64 @mock.should_receive(:random_call).at_most(:once)
65 @mock.random_call
66 @mock.rspec_verify
67 end
68
69 it "should pass when at most once method is never called" do
70 @mock.should_receive(:random_call).at_most(:once)
71 @mock.rspec_verify
72 end
73
74 it "should pass when at most twice method is called once" do
75 @mock.should_receive(:random_call).at_most(:twice)
76 @mock.random_call
77 @mock.rspec_verify
78 end
79
80 it "should pass when at most twice method is called twice" do
81 @mock.should_receive(:random_call).at_most(:twice)
82 @mock.random_call
83 @mock.random_call
84 @mock.rspec_verify
85 end
86
87 it "should pass when at most twice method is never called" do
88 @mock.should_receive(:random_call).at_most(:twice)
89 @mock.rspec_verify
90 end
91 end
92 end
93end