/
twice_counts_spec.rb
66 lines (58 loc) · 1.96 KB
/
twice_counts_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
require 'spec_helper'
module RSpec
module Mocks
describe "#twice" do
before(:each) do
@double = double("test double")
end
it "passes when called twice" do
@double.should_receive(:do_something).twice
@double.do_something
@double.do_something
@double.rspec_verify
end
it "passes when called twice with specified args" do
@double.should_receive(:do_something).twice.with("1", 1)
@double.do_something("1", 1)
@double.do_something("1", 1)
@double.rspec_verify
end
it "passes when called twice with unspecified args" do
@double.should_receive(:do_something).twice
@double.do_something("1")
@double.do_something(1)
@double.rspec_verify
end
it "fails fast when call count is higher than expected" do
@double.should_receive(:do_something).twice
@double.do_something
@double.do_something
lambda do
@double.do_something
end.should raise_error(RSpec::Mocks::MockExpectationError)
end
it "fails when call count is lower than expected" do
@double.should_receive(:do_something).twice
@double.do_something
lambda do
@double.rspec_verify
end.should raise_error(RSpec::Mocks::MockExpectationError)
end
it "fails when called wrong args on the first call" do
@double.should_receive(:do_something).twice.with("1", 1)
lambda do
@double.do_something(1, "1")
end.should raise_error(RSpec::Mocks::MockExpectationError)
@double.rspec_reset
end
it "fails when called with wrong args on the second call" do
@double.should_receive(:do_something).twice.with("1", 1)
@double.do_something("1", 1)
lambda do
@double.do_something(1, "1")
end.should raise_error(RSpec::Mocks::MockExpectationError)
@double.rspec_reset
end
end
end
end