|
7 | 7 | (deftest called?-works
|
8 | 8 | (testing "a spy was called directly"
|
9 | 9 | (bond/with-spy [target/foo]
|
10 |
| - (let [_ (target/foo 1)] |
11 |
| - (is (assertions/called? target/foo))))) |
| 10 | + (target/foo 1) |
| 11 | + (is (assertions/called? target/foo)))) |
12 | 12 |
|
13 | 13 | (testing "a spy was called indirectly"
|
14 | 14 | (bond/with-spy [target/foo]
|
15 |
| - (let [_ (target/foo-caller 1)] |
16 |
| - (is (assertions/called? target/foo))))) |
| 15 | + (target/foo-caller 1) |
| 16 | + (is (assertions/called? target/foo)))) |
17 | 17 |
|
18 | 18 | (testing "a spy was not called"
|
19 | 19 | (bond/with-spy [target/foo]
|
|
26 | 26 | (deftest called-times?-works
|
27 | 27 | (testing "the number of times a spy was called"
|
28 | 28 | (bond/with-spy [target/foo]
|
29 |
| - (let [_ (target/foo-caller 1)] |
30 |
| - (is (assertions/called-times? target/foo 1 ))) |
31 |
| - (let [_ (target/foo 2)] |
32 |
| - (is (assertions/called-times? target/foo 2))))) |
| 29 | + (target/foo-caller 1) |
| 30 | + (is (assertions/called-times? target/foo 1)) |
| 31 | + (target/foo 2) |
| 32 | + (is (assertions/called-times? target/foo 2)))) |
33 | 33 |
|
34 | 34 | (testing "the number of times a spy was not called"
|
35 | 35 | (bond/with-spy [target/foo]
|
36 |
| - (let [_ (target/foo-caller 1)] |
37 |
| - (is (not (assertions/called-times? target/foo 2)))) |
38 |
| - (let [_ (target/foo-caller 2)] |
39 |
| - (is (not (assertions/called-times? target/foo 1)))))) |
| 36 | + (target/foo-caller 1) |
| 37 | + (is (not (assertions/called-times? target/foo 2))) |
| 38 | + (target/foo-caller 2) |
| 39 | + (is (not (assertions/called-times? target/foo 1))))) |
40 | 40 |
|
41 | 41 | (testing "called-times? fails when its argument is not spied"
|
42 | 42 | (is (thrown? IllegalArgumentException
|
|
46 | 46 | (testing "an assertion for calling a spy with args"
|
47 | 47 | (bond/with-spy [target/foo
|
48 | 48 | target/bar]
|
49 |
| - (let [_ (target/foo-caller 1)] |
50 |
| - (is (assertions/called-with-args? target/foo [[1]])) |
51 |
| - (is (not (assertions/called-with-args? target/foo [[2]]))) |
52 |
| - (is (not (assertions/called-with-args? target/bar [[1]]))) |
53 |
| - (is (not (assertions/called-with-args? target/foo [[1 2]])))))) |
| 49 | + (target/foo-caller 1) |
| 50 | + (is (assertions/called-with-args? target/foo [[1]])) |
| 51 | + (is (not (assertions/called-with-args? target/foo [[2]]))) |
| 52 | + (is (not (assertions/called-with-args? target/bar [[1]]))) |
| 53 | + (is (not (assertions/called-with-args? target/foo [[1 2]]))))) |
54 | 54 |
|
55 | 55 | (testing "an assertion for calling a spy multiple times with args"
|
56 | 56 | (bond/with-spy [target/foo]
|
57 |
| - (let [_ (do (target/foo-caller 1) |
58 |
| - (target/foo-caller 2))] |
59 |
| - (is (assertions/called-with-args? target/foo [[1] [2]]))))) |
| 57 | + (target/foo-caller 1) |
| 58 | + (target/foo-caller 2) |
| 59 | + (is (assertions/called-with-args? target/foo [[1] [2]])))) |
60 | 60 |
|
61 | 61 | (testing "called-with-args? fails when its argument is not spied"
|
62 | 62 | (is (thrown? IllegalArgumentException
|
63 | 63 | (assertions/called-with-args? target/foo [])))))
|
| 64 | + |
| 65 | +(deftest called-once-with-args?-works |
| 66 | + (testing "an assertion for calling a spy once with args" |
| 67 | + (bond/with-spy [target/foo] |
| 68 | + (target/foo 1) |
| 69 | + (is (assertions/called-once-with-args? target/foo [1])) |
| 70 | + (is (not (assertions/called-once-with-args? target/foo [2]))))) |
| 71 | + |
| 72 | + (testing "an assertion for calling a spy twice with args" |
| 73 | + (bond/with-spy [target/foo] |
| 74 | + (target/foo 1) |
| 75 | + (target/foo 2) |
| 76 | + (is (not (assertions/called-once-with-args? target/foo [1]))) |
| 77 | + (is (not (assertions/called-once-with-args? target/foo [2]))))) |
| 78 | + |
| 79 | + (testing "an assertion for calling a spy indirectly once with args" |
| 80 | + (bond/with-spy [target/foo] |
| 81 | + (target/foo-caller 1) |
| 82 | + (is (assertions/called-once-with-args? target/foo [1])) |
| 83 | + (is (not (assertions/called-once-with-args? target/foo [2]))))) |
| 84 | + |
| 85 | + (testing "an assertion for a spy that was not called" |
| 86 | + (bond/with-spy [target/foo] |
| 87 | + (is (not (assertions/called-once-with-args? target/foo []))))) |
| 88 | + |
| 89 | + (testing "called-once-with-args? fails when its argument is not spied" |
| 90 | + (is (thrown? IllegalArgumentException |
| 91 | + (assertions/called-once-with-args? target/foo []))))) |
| 92 | + |
| 93 | +(deftest called-at-least-once-with-args?-works |
| 94 | + (testing "an assertion for calling a spy multiple times" |
| 95 | + (bond/with-spy [target/foo] |
| 96 | + (target/foo 1) |
| 97 | + (target/foo 2) |
| 98 | + (is (assertions/called-at-least-once-with-args? target/foo [1])) |
| 99 | + (is (assertions/called-at-least-once-with-args? target/foo [2])) |
| 100 | + (is (not (assertions/called-at-least-once-with-args? target/foo [3]))))) |
| 101 | + |
| 102 | + (testing "an assertion for calling a spy multiple times with the same value" |
| 103 | + (bond/with-spy [target/foo] |
| 104 | + (target/foo 1) |
| 105 | + (target/foo 1) |
| 106 | + (is (assertions/called-at-least-once-with-args? target/foo [1])) |
| 107 | + (is (not (assertions/called-at-least-once-with-args? target/foo [2]))))) |
| 108 | + |
| 109 | + (testing "an assertion for calling a spy once" |
| 110 | + (bond/with-spy [target/foo] |
| 111 | + (target/foo 1) |
| 112 | + (is (assertions/called-at-least-once-with-args? target/foo [1])) |
| 113 | + (is (not (assertions/called-at-least-once-with-args? target/foo [2]))))) |
| 114 | + |
| 115 | + (testing "an assertion for a spy that was not called" |
| 116 | + (bond/with-spy [target/foo] |
| 117 | + (is (not (assertions/called-at-least-once-with-args? target/foo []))))) |
| 118 | + |
| 119 | + (testing "called-at-least-once-with-args? fails when its argument is not spied" |
| 120 | + (is (thrown? IllegalArgumentException |
| 121 | + (assertions/called-at-least-once-with-args? target/foo []))))) |
0 commit comments