Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: None  |  size: 3.04 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ;; Current version -- note the use of `when-valid`... it is essentially duplicating the work the
  2. ;; syntax-validation-m monad should be able to handle, so I've been attempting to
  3. ;; clean it up / refactor it to use only the monad
  4.  
  5. (defmacro expect
  6.   "Run the call form, check that all the mocks defined in the fakes
  7. (probably with 'fake') have been satisfied, and check that the actual
  8. results are as expected. If the expected results are a function, it
  9. will be called with the actual result as its single argument.
  10.  
  11. To strip tests from production code, set either clojure.test/*load-tests*,
  12. midje.semi-sweet/*include-midje-checks*, or midje.sweet/*include-midje-checks* to false."
  13.   {:arglists '([call-form arrow expected-result & fakes+overrides])}
  14.   [& _]
  15.   (when (user-desires-checking?)
  16.     (domonad syntax-validate-m [[call-form arrow expected-result & fakes+overrides] (validate &form)
  17.                                 [fakes overrides] (separate-by a-fake? fakes+overrides)]
  18.       (when-valid fakes
  19.         (expect-expansion call-form arrow expected-result fakes overrides)))))
  20.  
  21. ;; New attempted version--  which I have no reason to believe should not work (but doesn't):
  22. (defmacro expect
  23.   "Run the call form, check that all the mocks defined in the fakes
  24.    (probably with 'fake') have been satisfied, and check that the actual
  25.    results are as expected. If the expected results are a function, it
  26.    will be called with the actual result as its single argument.
  27.  
  28.    To strip tests from production code, set either clojure.test/*load-tests*,
  29.    midje.semi-sweet/*include-midje-checks*, or midje.sweet/*include-midje-checks* to false."
  30.   {:arglists '([call-form arrow expected-result & fakes+overrides])}
  31.   [& _]
  32.   (when (user-desires-checking?)
  33.     (domonad syntax-validate-m [[call-form arrow expected-result & fakes+overrides] (validate &form)
  34.                                 [unvalidated-fakes overrides] (separate-by a-fake? fakes+overrides)
  35.                                 fakes (validate unvalidated-fakes)]
  36.       (expect-expansion call-form arrow expected-result fakes overrides))))
  37.  
  38. ;; UPDATE --
  39. ;; looks like this works, but I'd really prefer the above version over this, but I might not fight it
  40.  
  41. (defmacro expect
  42.   "Run the call form, check that all the mocks defined in the fakes
  43.    (probably with 'fake') have been satisfied, and check that the actual
  44.    results are as expected. If the expected results are a function, it
  45.    will be called with the actual result as its single argument.
  46.  
  47.    To strip tests from production code, set either clojure.test/*load-tests*,
  48.    midje.semi-sweet/*include-midje-checks*, or midje.sweet/*include-midje-checks* to false."
  49.   {:arglists '([call-form arrow expected-result & fakes+overrides])}
  50.   [& _]
  51.   (when (user-desires-checking?)
  52.     (domonad syntax-validate-m [[call-form arrow expected-result & fakes+overrides] (validate &form)
  53.                                 [fakes overrides] (separate-by a-fake? fakes+overrides)
  54.                                 _ (validate fakes)]
  55.       (expect-expansion call-form arrow expected-result fakes overrides))))