~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/rspec/spec/spec/mocks/at_least_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080726154345-c03m49twzxewdwjn
Tags: 0.24.5-2
* Fix puppetlast to work with 0.24.5
* Adjust logcheck to match against new log messages in 0.24.5
* Update standards version to 3.8.0 (no changes)
* Update changelog to reduce length of line to make lintian happy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require File.dirname(__FILE__) + '/../../spec_helper.rb'
 
2
 
 
3
module Spec
 
4
  module Mocks
 
5
    describe "at_least" do
 
6
      before(:each) do
 
7
        @mock = Mock.new("test mock")
 
8
      end
 
9
 
 
10
      it "should fail if method is never called" do
 
11
        @mock.should_receive(:random_call).at_least(4).times
 
12
          lambda do
 
13
        @mock.rspec_verify
 
14
        end.should raise_error(MockExpectationError)
 
15
      end
 
16
 
 
17
      it "should fail when called less than n times" do
 
18
        @mock.should_receive(:random_call).at_least(4).times
 
19
        @mock.random_call
 
20
        @mock.random_call
 
21
        @mock.random_call
 
22
        lambda do
 
23
          @mock.rspec_verify
 
24
        end.should raise_error(MockExpectationError)
 
25
      end
 
26
 
 
27
      it "should fail when at least once method is never called" do
 
28
        @mock.should_receive(:random_call).at_least(:once)
 
29
        lambda do
 
30
          @mock.rspec_verify
 
31
        end.should raise_error(MockExpectationError)
 
32
      end
 
33
 
 
34
      it "should fail when at least twice method is called once" do
 
35
        @mock.should_receive(:random_call).at_least(:twice)
 
36
        @mock.random_call
 
37
        lambda do
 
38
          @mock.rspec_verify
 
39
        end.should raise_error(MockExpectationError)
 
40
      end
 
41
 
 
42
      it "should fail when at least twice method is never called" do
 
43
        @mock.should_receive(:random_call).at_least(:twice)
 
44
        lambda do
 
45
          @mock.rspec_verify
 
46
        end.should raise_error(MockExpectationError)
 
47
      end
 
48
 
 
49
      it "should pass when at least n times method is called exactly n times" do
 
50
        @mock.should_receive(:random_call).at_least(4).times
 
51
        @mock.random_call
 
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 least n times method is called n plus 1 times" do
 
59
        @mock.should_receive(:random_call).at_least(4).times
 
60
        @mock.random_call
 
61
        @mock.random_call
 
62
        @mock.random_call
 
63
        @mock.random_call
 
64
        @mock.random_call
 
65
        @mock.rspec_verify
 
66
      end
 
67
 
 
68
      it "should pass when at least once method is called once" do
 
69
        @mock.should_receive(:random_call).at_least(:once)
 
70
        @mock.random_call
 
71
        @mock.rspec_verify
 
72
      end
 
73
 
 
74
      it "should pass when at least once method is called twice" do
 
75
        @mock.should_receive(:random_call).at_least(:once)
 
76
        @mock.random_call
 
77
        @mock.random_call
 
78
        @mock.rspec_verify
 
79
      end
 
80
 
 
81
      it "should pass when at least twice method is called three times" do
 
82
        @mock.should_receive(:random_call).at_least(:twice)
 
83
        @mock.random_call
 
84
        @mock.random_call
 
85
        @mock.random_call
 
86
        @mock.rspec_verify
 
87
      end
 
88
 
 
89
      it "should pass when at least twice method is called twice" do
 
90
        @mock.should_receive(:random_call).at_least(:twice)
 
91
        @mock.random_call
 
92
        @mock.random_call
 
93
        @mock.rspec_verify
 
94
      end
 
95
    end
 
96
  end
 
97
end