Skip to content

Commit

Permalink
Merge pull request #180 from nubank/tutorial-defflow
Browse files Browse the repository at this point in the history
Defflow in tutorial
  • Loading branch information
kdmoreira authored Dec 13, 2024
2 parents 4f2f888 + d39dfe3 commit 8aeec82
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

StateFlow is a testing framework designed to support the composition and reuse of individual test steps.

## Learning Materials
- [Tutorial](./samples/tutorial.clj)
- [Walkthrough](./doc/walkthrough.repl)

## Definitions

* A [*flow*](#flows) is a sequence of steps or bindings.
Expand Down
53 changes: 43 additions & 10 deletions samples/tutorial.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns state-flow.presentation
(:require [state-flow.api :as api :refer [flow match?]]))
(:require [state-flow.api :as api :refer [flow match? defflow]]))

"""
The primitive steps
Expand Down Expand Up @@ -58,17 +58,50 @@ Bindings
Tests
(match? <description> <value/flow> <matcher>)
(defflow <name> [parameters] <flows>)
"""
(def with-assertions
(flow "with assertions"
inc-value
[value get-value]
(match? 5 value)
(def with-matching-assertion
(flow "truthy assertion"
inc-value
[value get-value]
(match? 5 value)))
(api/run with-matching-assertion {:value 4})
; => [{:match/result :match ...}]

(def with-mismatched-assertion
(flow "falsy assertion"
inc-value
[value get-value]
(match? 6 value)))
(api/run with-mismatched-assertion {:value 4})
; => [{:match/result :mismatch ...}]

(def with-matching-and-mismatched-assertions
(flow "falsy assertion before truthy ones"
inc-value
[value get-value]
(match? 0 value) ; mismatch

inc-value
[value get-value]
(match? 6 value) ; match

inc-value
[world (api/get-state identity)]
(match? {:value 7} world))) ; match
(api/run with-matching-and-mismatched-assertions {:value 4})
; => [{:match/result :match ...}]

(defflow my-test
{:init (constantly {:value 4})}
with-matching-and-mismatched-assertions)

(comment
(my-test)
; actual: (mismatch (expected 0) (actual 5))
)

inc-value
[world (api/get-state identity)]
(match? 7 get-value)))
(api/run with-assertions {:value 4})

"""
Asynchronous tests
Expand Down

0 comments on commit 8aeec82

Please sign in to comment.