File: thrice_counts_spec.rb

package info (click to toggle)
ruby-rspec 3.5.0c3e0m0s0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,312 kB
  • ctags: 4,788
  • sloc: ruby: 62,572; sh: 785; makefile: 100
file content (72 lines) | stat: -rw-r--r-- 2,108 bytes parent folder | download | duplicates (2)
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
module RSpec
  module Mocks
    RSpec.describe "#thrice" do
      before(:each) do
        @double = double("test double")
      end

      it "passes when called thrice" do
        expect(@double).to receive(:do_something).thrice
        3.times { @double.do_something }
        verify @double
      end

      it "passes when called thrice with specified args" do
        expect(@double).to receive(:do_something).thrice.with("1", 1)
        3.times { @double.do_something("1", 1) }
        verify @double
      end

      it "passes when called thrice with unspecified args" do
        expect(@double).to receive(:do_something).thrice
        @double.do_something("1")
        @double.do_something(1)
        @double.do_something(nil)
        verify @double
      end

      it "fails fast when call count is higher than expected" do
        expect(@double).to receive(:do_something).thrice
        3.times { @double.do_something }
        expect_fast_failure_from(@double) do
          @double.do_something
        end
      end

      it "fails when call count is lower than expected" do
        expect(@double).to receive(:do_something).thrice
        @double.do_something
        expect {
          verify @double
        }.to fail
      end

      it "fails when called with wrong args on the first call" do
        expect(@double).to receive(:do_something).thrice.with("1", 1)
        expect {
          @double.do_something(1, "1")
        }.to fail
        reset @double
      end

      it "fails when called with wrong args on the second call" do
        expect(@double).to receive(:do_something).thrice.with("1", 1)
        @double.do_something("1", 1)
        expect {
          @double.do_something(1, "1")
        }.to fail
        reset @double
      end

      it "fails when called with wrong args on the third call" do
        expect(@double).to receive(:do_something).thrice.with("1", 1)
        @double.do_something("1", 1)
        @double.do_something("1", 1)
        expect {
          @double.do_something(1, "1")
        }.to fail
        reset @double
      end
    end
  end
end