Skip to content

Instantly share code, notes, and snippets.

@gigasquid
Forked from AlexBaranosky/gist:2296469
Created April 4, 2012 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigasquid/2296953 to your computer and use it in GitHub Desktop.
Save gigasquid/2296953 to your computer and use it in GitHub Desktop.
;; Current version -- note the use of `when-valid`... it is essentially duplicating the work the
;; syntax-validation-m monad should be able to handle, so I've been attempting to
;; clean it up / refactor it to use only the monad
(defmacro expect
"Run the call form, check that all the mocks defined in the fakes
(probably with 'fake') have been satisfied, and check that the actual
results are as expected. If the expected results are a function, it
will be called with the actual result as its single argument.
To strip tests from production code, set either clojure.test/*load-tests*,
midje.semi-sweet/*include-midje-checks*, or midje.sweet/*include-midje-checks* to false."
{:arglists '([call-form arrow expected-result & fakes+overrides])}
[& _]
(when (user-desires-checking?)
(domonad syntax-validate-m [[call-form arrow expected-result & fakes+overrides] (validate &form)
[fakes overrides] (separate-by a-fake? fakes+overrides)]
(when-valid fakes
(expect-expansion call-form arrow expected-result fakes overrides)))))
;; New attempted version-- which I have no reason to believe should not work (but doesn't):
(defmacro expect
"Run the call form, check that all the mocks defined in the fakes
(probably with 'fake') have been satisfied, and check that the actual
results are as expected. If the expected results are a function, it
will be called with the actual result as its single argument.
To strip tests from production code, set either clojure.test/*load-tests*,
midje.semi-sweet/*include-midje-checks*, or midje.sweet/*include-midje-checks* to false."
{:arglists '([call-form arrow expected-result & fakes+overrides])}
[& _]
(when (user-desires-checking?)
(domonad syntax-validate-m [[call-form arrow expected-result & fakes+overrides] (validate &form)
[unvalidated-fakes overrides] (separate-by a-fake? fakes+overrides)
fakes (validate unvalidated-fakes)]
(expect-expansion call-form arrow expected-result fakes overrides))))
;; UPDATE --
;; looks like this works, but I'd really prefer the above version over this, but I might not fight it
(defmacro expect
"Run the call form, check that all the mocks defined in the fakes
(probably with 'fake') have been satisfied, and check that the actual
results are as expected. If the expected results are a function, it
will be called with the actual result as its single argument.
To strip tests from production code, set either clojure.test/*load-tests*,
midje.semi-sweet/*include-midje-checks*, or midje.sweet/*include-midje-checks* to false."
{:arglists '([call-form arrow expected-result & fakes+overrides])}
[& _]
(when (user-desires-checking?)
(domonad syntax-validate-m [[call-form arrow expected-result & fakes+overrides] (validate &form)
[fakes overrides] (separate-by a-fake? fakes+overrides)
_ (validate fakes)]
(expect-expansion call-form arrow expected-result fakes overrides))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment