with-state-changes and function calls

3 views
Skip to first unread message

David Nies

unread,
Jul 6, 2015, 9:40:26 AM7/6/15
to mi...@googlegroups.com
Hello!

The following code works (obviously):

(with-state-changes [(before :contents (println "before") :after (println "after))]
  (fact "one" 
    (println "doin' 1")
    1 => 1)
  (fact "two"
    (println "doin' 2")
    (+ 1 1) => 2))

The output is the expected one:

before
doin' 1
doin' 2
after

Everything fine. But now, I want my facts to be contained in a separate function and call this function inside `with-state-changes` like so:

(defn my-facts []
  (fact "fact1" ...)
  (fact "fact2" ...)
  #_( ... ))

(with-state-changes [(before :contents (println "setup") :after (println "teardown))]
  (my-facts))

But this does not work, I get an error like this:

    Midje could not understand something you wrote: 

        Background prerequisites created by the wrapping version of

        `against-background` only affect nested facts. This one

        wraps no facts.

        

        Note: if you want to supply a background to all checks in a fact, 

        use the non-wrapping form. That is, instead of this:

            (fact 

              (against-background [(f 1) => 1] 

                (g 3 2 1) => 8 

                (h 1 2) => 7)) 

        ... use this:

            (fact 

              (g 3 2 1) => 8 

              (h 1 2) => 7 

              (against-background (f 1) => 1)) 


So it does not handle function calls as I'd expect it to. How can I achieve my goal? I want to use midje's setup- and teardown facilities but I also want to have my facts (around which the setup- and teardown work) to be contained in a separate fn.

Thank you very much!

-David

Reply all
Reply to author
Forward
0 new messages