forked from rspec/rspec-mocks
/
at_least_spec.rb
103 lines (90 loc) · 3.09 KB
/
at_least_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'spec_helper'
module RSpec
module Mocks
describe "at_least" do
before(:each) do
@mock = RSpec::Mocks::Mock.new("test mock")
end
it "fails if method is never called" do
@mock.should_receive(:random_call).at_least(4).times
lambda do
@mock.rspec_verify
end.should raise_error(RSpec::Mocks::MockExpectationError)
end
it "fails when called less than n times" do
@mock.should_receive(:random_call).at_least(4).times
@mock.random_call
@mock.random_call
@mock.random_call
lambda do
@mock.rspec_verify
end.should raise_error(RSpec::Mocks::MockExpectationError)
end
it "fails when at least once method is never called" do
@mock.should_receive(:random_call).at_least(:once)
lambda do
@mock.rspec_verify
end.should raise_error(RSpec::Mocks::MockExpectationError)
end
it "fails when at least twice method is called once" do
@mock.should_receive(:random_call).at_least(:twice)
@mock.random_call
lambda do
@mock.rspec_verify
end.should raise_error(RSpec::Mocks::MockExpectationError)
end
it "fails when at least twice method is never called" do
@mock.should_receive(:random_call).at_least(:twice)
lambda do
@mock.rspec_verify
end.should raise_error(RSpec::Mocks::MockExpectationError)
end
it "passes when at least n times method is called exactly n times" do
@mock.should_receive(:random_call).at_least(4).times
@mock.random_call
@mock.random_call
@mock.random_call
@mock.random_call
@mock.rspec_verify
end
it "passes when at least n times method is called n plus 1 times" do
@mock.should_receive(:random_call).at_least(4).times
@mock.random_call
@mock.random_call
@mock.random_call
@mock.random_call
@mock.random_call
@mock.rspec_verify
end
it "passes when at least once method is called once" do
@mock.should_receive(:random_call).at_least(:once)
@mock.random_call
@mock.rspec_verify
end
it "passes when at least once method is called twice" do
@mock.should_receive(:random_call).at_least(:once)
@mock.random_call
@mock.random_call
@mock.rspec_verify
end
it "passes when at least twice method is called three times" do
@mock.should_receive(:random_call).at_least(:twice)
@mock.random_call
@mock.random_call
@mock.random_call
@mock.rspec_verify
end
it "passes when at least twice method is called twice" do
@mock.should_receive(:random_call).at_least(:twice)
@mock.random_call
@mock.random_call
@mock.rspec_verify
end
it "returns the value given by a block when the at least once method is called" do
@mock.should_receive(:to_s).at_least(:once) { "testing" }
@mock.to_s.should == "testing"
@mock.rspec_verify
end
end
end
end