Skip to content

Commit

Permalink
Merge pull request #128 from nubank/dc/improve-error-message
Browse files Browse the repository at this point in the history
improve error message when last arg to flow is a vector
  • Loading branch information
dchelimsky authored Jun 8, 2020
2 parents 3df23c7 + b591362 commit ea483e5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [5.1.0]

* improve error message when last arg to flow is a vector [#128](https://github.com/nubank/state-flow/pull/128)

## [5.0.0]

* upgrade to matcher-combinators-2.0.0
Expand All @@ -13,7 +17,7 @@ See https://github.com/nubank/matcher-combinators/blob/master/CHANGELOG.md#200

## [4.0.3]

* `state-flow.api/match?` throws `times-to-try` exception at runtime instead of macro-expansion time [#125](https://github.com/nubank/state-flow/pull/125)
* `state-flow.api/match?` throws `times-to-try` exception a runtime instead of macro-expansion time [#125](https://github.com/nubank/state-flow/pull/125)
* The deprecated `state-flow.cljtest/match?` no longer throws that exception at all.

## [4.0.2]
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject nubank/state-flow "5.0.0"
(defproject nubank/state-flow "5.1.0"
:description "Integration testing with composable flows"
:url "https://github.com/nubank/state-flow"
:license {:name "MIT"}
Expand Down
2 changes: 2 additions & 0 deletions src/state_flow/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
[{:keys [description caller-meta]} & flows]
(when-not (string-expr? description)
(throw (IllegalArgumentException. "The first argument to flow must be a description string")))
(when (vector? (last flows))
(throw (ex-info "The last argument to flow must be a flow/step, not a binding vector." {})))
(let [flow-meta caller-meta
flows' (or flows `[(m/return nil)])]
`(m/do-let
Expand Down
22 changes: 16 additions & 6 deletions test/state_flow/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
(def empty-flow
(flow "empty"))

(deftest test-flow
(testing "flow without description fails at macro-expansion time"
(is (re-find #"first argument .* must be .* description string"
(try
(macroexpand `(flow (state/return {})))
(catch clojure.lang.Compiler$CompilerException e
(.. e getCause getMessage))))))

(testing "flow with vector as last argument fails at macro-expansion time"
(is (re-find #"last argument .* must be a flow/step"
(try
(macroexpand `(flow "" [x (state/get-state)]))
(catch clojure.lang.Compiler$CompilerException e
(.. e getCause getMessage)))))))

(deftest run-flow
(testing "default initial state is an empty map"
(is (= {}
Expand All @@ -49,12 +64,7 @@
(testing "empty flow runs without exception"
(is (nil? (first (state-flow/run empty-flow {})))))

(testing "flow without description fails at macro-expansion time"
(is (re-find #"first argument .* must be .* description string"
(try
(macroexpand `(flow (state/return {})))
(catch clojure.lang.Compiler$CompilerException e
(.. e getCause getMessage))))))


(testing "flow with a `(str ..)` expr for the description is fine"
(is (macroexpand `(flow (str "foo") [original (state/gets :value)
Expand Down

0 comments on commit ea483e5

Please sign in to comment.