Skip to content

Loading…

Cannot "compile" midje facts when wrapping two macros that has with-state-changes #205

Closed
petterik opened this Issue · 5 comments

3 participants

@petterik

I'm using macros to wrap some of my facts in common with-state-changes.
The two macros I'm using so far are "with-server" and "with-memory-store". They are defined as:

(defmacro with-memory-store [& body]
  `(let [db# @db/db]
    (midje/facts
      (midje/with-state-changes [(midje/before :contents (reset! db/db (mem/get-instance)))
                                 (midje/after :facts (reset-memory!))
                                 (midje/after :contents (reset! db/db db#))]
        (midje/fact 1 midje/=> 1)
        ~@body))))
(defmacro with-server [& body]
  `(let [server# (start-server)]
     (midje/facts
       (midje/with-state-changes [(midje/after :contents (server#))]
         (midje/fact 1 midje/=> 1)
         ~@body))))

They won't compile for me when I wrap them as (with-server (with-memory-store (facts ...))), if I don't use the middle "dummy fact" (midje/fact 1 midje/=> 1). With out those facts I get "Midje could not understand something you wrote:..."

Please let me know if you have another way achieving the same thing, or if there's anything that's unclear.

@josephwilk

Which version of Midje are you using?

There was a bug in 1.5.0 where it failed parsing valid structures. Maybe try 1.5.1?

I've mainly used: (namespace-state-changes [(before :facts (reset! state 0))])
But that's for a whole namespace rather than specific scopes..

@petterik

Having the same problem with 1.5.1

@marick
Owner

Sorry for the delay - I've been traveling for a month.

When I try to reproduce your problem with a single file, I get no failure. Here's the source:

(ns scratch.default-test
  (:require [midje.sweet :as midje]))

(def db (atom 0))

(defmacro with-memory-store [& body]
  `(let [db# @db]
    (midje/facts
      (midje/with-state-changes [(midje/before :contents (reset! db 3))
                           (midje/after :facts (fn []))
                           (midje/after :contents (reset! db db#))]
;        (midje/fact 1 => 1)
        ~@body))))

(with-memory-store
  (midje/fact 1 => 1))

(defmacro with-server [& body]
  `(let [server# (fn [])]
     (midje/facts
       (midje/with-state-changes [(after :contents (server#))]
;         (midje/fact 1 => 1)
         ~@body))))

(with-server
  (midje/fact 1 => 1))

I get All checks (2) succeeded.

Does this work for you? If so, can you provide me with a runnable example that fails?

@marick
Owner

Belay that. I see that I do get a failure with this:

(with-server (with-memory-store (midje/fact 1 => 1)))
@marick
Owner

Fixed in 1.6-SNAPSHOT

@marick marick closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.