-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmidje_test.clj
34 lines (29 loc) · 1.62 KB
/
midje_test.clj
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
(ns state-flow.midje-test
(:require [clojure.test :as t :refer [deftest is testing]]
[midje.sweet :refer [contains just]]
[state-flow.core :as state-flow]
[state-flow.midje :as midje]
[state-flow.state :as state]
[state-flow.test-helpers :as test-helpers]))
(deftest verify
(testing "doesn't change state when state-fn doesn't change state"
(let [[ret state] (state-flow/run (midje/verify "description" test-helpers/add-two 3) {:value 1})]
(is (= 3 ret))
(is (= {:value 1} state))))
(testing "works with non-state values"
(is (= 3 (first (state-flow/run (midje/verify "description" 3 3) {})))))
(testing "add two with small delay"
(let [state {:value (atom 0)}]
(is (= 0 @(:value (first (state-flow/run (test-helpers/delayed-add-two 100) state)))))
(is (= 2 (first (state-flow/run (midje/verify "description" test-helpers/get-value-state 2) state))))))
(testing "add two with too much delay"
(let [state {:value (atom 0)}]
(is (= 0 @(:value (first (state-flow/run (test-helpers/delayed-add-two 4000) state)))))
(is (= 0 (first (state-flow/run (midje/verify "description" test-helpers/get-value-state 0) state))))))
(testing "extended equality"
(let [state {:a 2 :b 5}]
(= state
(first (state/run (midje/verify-probe "contains with monadic left value"
(state/get) (contains {:a 2}) {}) state))
(first (state/run (midje/verify-probe "just with monadic left value"
(state/get) (just {:a 2 :b 5}) {}) state))))))