Created
April 3, 2012 23:56
-
-
Save AlexBaranosky/2296469 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 1. 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))))) | |
;; 2. 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 -- | |
;; 3. 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)))) |
Does this work? (last item on the gist) https://gist.github.com/2296961 (curious)
Tried it; doesn't seem to work. Honestly, it looks like #2 above should work, but doesn't. That's what's so annoying about it -- I don't like allowing bugs to defeat me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well - my thoughts after just looking (could be totally off-base) but -
In the original version
Then when-valid called the syntax-validate on [# (validate ~validatable-form)] - which would be [# (validate fakes)]
In the new attempted version, the fakes is not in the same form ... vector
Would wrapping the fakes in a similar vector form work?