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

Closed
petterik opened this Issue Mar 31, 2013 · 5 comments

Comments

Projects
None yet
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

This comment has been minimized.

Show comment
Hide comment
@josephwilk

josephwilk Apr 1, 2013

Contributor

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..

Contributor

josephwilk commented Apr 1, 2013

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

This comment has been minimized.

Show comment
Hide comment
@petterik

petterik Apr 2, 2013

Having the same problem with 1.5.1

petterik commented Apr 2, 2013

Having the same problem with 1.5.1

@marick

This comment has been minimized.

Show comment
Hide comment
@marick

marick May 8, 2013

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?

Owner

marick commented May 8, 2013

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

This comment has been minimized.

Show comment
Hide comment
@marick

marick May 8, 2013

Owner

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

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

marick commented May 8, 2013

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

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

This comment has been minimized.

Show comment
Hide comment
@marick

marick May 9, 2013

Owner

Fixed in 1.6-SNAPSHOT

Owner

marick commented May 9, 2013

Fixed in 1.6-SNAPSHOT

@marick marick closed this May 9, 2013

marick added a commit that referenced this issue May 9, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment