Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defflow in tutorial #180

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading