with-state-changes runs even when fact-group is filtered out

21 views
Skip to first unread message

Joe Littlejohn

unread,
Jul 28, 2015, 11:21:03 AM7/28/15
to Midje
Hi all,

I have some facts that use with-state-changes ('before :contents' and 'after :contents'). The facts look like this:

(fact-group
 :integration

 (with-state-changes [(before :contents (setup-stateful-thing))
                      (after :contents (teardown-stateful-thing))]
   
   (fact "some fact"
         ...)

   (fact "some other fact"
         ...)))

These are integration tests with some costly setup and teardown that I don't typically want to execute. When I run my tests, by default these tests are filtered out (filter: -integration) however I can see from the logs that with-state-changes before and after a still running, even when the filter is -integration.

I assume the problem here is that fact-group simply passes on metadata to its facts, and it's the facts themselves that are filtered out.

Is there any way to have setup/teardown for integration/acceptance tests (or any group/category of tests), and stop this from running when one needs to run some other group of tests?

Cheers

Brian Marick

unread,
Jul 28, 2015, 2:45:36 PM7/28/15
to mi...@googlegroups.com
You could try changing the `fact-group` to a `fact`, like this:

(facts :integration
(with-state-changes [...]
(fact "1" ...)
(fact "2" ...)))

I think that should work, though I haven't tried it.

This will prevent you from running only one of "1" and "2".

I'm not convinced `fact-group` was a good idea.
> --
> You received this message because you are subscribed to the Google
> Groups "Midje" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to midje+un...@googlegroups.com
> <mailto:midje+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Joe Littlejohn

unread,
Jul 29, 2015, 5:31:43 AM7/29/15
to Midje, mar...@exampler.com
Thanks Brian, I'm definitely getting closer using on your advice.

I think there may be a bug here in how metadata is passed from the parent fact to children. The docs state that metadata on the inner facts is ignored (and as you mention, this prevents facts inside the parent fact being selected individually). I've found the opposite is true, metadata from the parent fact is not inherited by the children and only inner facts that explicitly match the filter are run.

So this:

(facts :integration 
  (with-state-changes [...] 
    (fact "1" ...) 
    (fact "2" ...))) 

Does avoid running the state changes when the filter is -integration (good) but none of the inner facts are run.

I've tried various things and the only thing that seems to work is:

(facts :integration 
  (with-state-changes [...] 
    (fact :integration "1" ...) 
    (fact :integration "2" ...))) 

This doesn't match the docs so I'm guessing it's a bug?

Thanks again for your help.

Joe

Joe Littlejohn

unread,
Jul 30, 2015, 4:22:03 AM7/30/15
to Midje, mar...@exampler.com, joelit...@gmail.com
I've created an issue with a simple example:


If I get a chance I'll try to submit a PR to test & fix this.

Cheers

Brian Marick

unread,
Aug 4, 2015, 3:52:04 PM8/4/15
to mi...@googlegroups.com, joelit...@gmail.com


Joe Littlejohn wrote:
> I've created an issue with a simple example:

Fixed in 1.8-alpha1.
Reply all
Reply to author
Forward
0 new messages