Midje
Midje copied to clipboard
Metadata filtering not working in groups
Hi,
First of all I'm pretty new to midje so my apologies if this is a mess-up on my part, but I think it might be an actual bug. I'm using midje 1.6.2 and clojure 1.5.1 .
Metadata filtering in fact groups doesn't seem to be working for me. If I create the following 2 example facts by themselves, everything is fine:
(fact :foo
(println "Test with metadata")
(+ 1 1) => 2)
(fact
(println "Test without metadata")
(+ 1 1) => 2)
I get:
user=> (load-facts :foo)
Test with metadata
All checks (1) succeeded.
{:failures 0}
user=> (load-facts (complement :foo))
Test without metadata
All checks (1) succeeded.
{:failures 0}
However if I put them in a group the metadata doesn't seem to take:
(facts
(fact :foo
(println "Test with metadata")
(+ 1 1) => 2)
(fact
(println "Test without metadata")
(+ 1 1) => 2))
user=> (load-facts :foo)
No facts were checked. Is that what you wanted?
{:failures 0}
If I put the metadata just on the outside group still no dice, and if I change the outside group from facts to fact still no go.
However if both the group and the fact is marked up, then the metadata applies:
(facts :foo
(fact :foo
(println "Test with metadata")
(+ 1 1) => 2)
(fact
(println "Test without metadata")
(+ 1 1) => 2))
user=> (load-facts :foo)
Test with metadata
All checks (1) succeeded.
{:failures 0}
Am I doing something wrong or is this a bug? I expected that I should be able to use metadata on a fact group, and it would apply to all facts within that group, or at least if applied metadata to facts in a group then they would actually have that metadata, even if the group did not.
Thanks
Mike
Same here. Seems like the nested facts don't have the metadata unless both they and all their ancestors have the metadata.
(facts :foo
(fact :foo
(fact :foo
(fact :foo
1 => 1))))
=> 1 :foo
(facts :foo
(fact :foo
(fact
(fact :foo
1 => 1))))
=> 0 :foo
https://github.com/marick/Midje/wiki/Metadata#short-version says it should work differently.
Use fact-group
instead of facts
.
Both of these examples should work as you would expect.
(fact-group
(facts :foo
1=>1))
(fact-group :foo
(facts
1=>1))
thanks! does the trick for these examples, I can live with this.
Should the documentation be updated or should this also work with fact
as documented?
nested fact-group
doesn't work btw:
(fact-group
(fact-group :foo
(fact
1 => 1)))
=> 0 :foo
@ikitommi I haven't participated in this project before, so I'm not sure which would be preferred. Updating docs would probably be easier.
There is documentation that explains about metadata on nested facts here: https://github.com/marick/Midje/wiki/Metadata
With the exception of the :midje/description (which is used to compose failure messages),
metadata in interior facts is ignored. You cannot, for example, choose to run only one
sub-fact of an outer fact.
But it was wrong for it not to be in https://github.com/marick/Midje/wiki/Using-metadata-to-filter-facts as well. Now it is.
@ikitommi Your example is a bug. It's interesting that "nearby" cases like these work:
(fact-group :outer (fact-group :inner (fact 1 => 1)))
(fact-group :outer (fact-group (fact 1 => 1)))
However, in your case, the :inner
keyword doesn't get added to the fact's metadata:
user=> (forget-facts :all)
true
user=> (fact-group (fact-group :inner (fact :f 1 => 1)))
true
;;; Note that `:f` is set, but not `:inner`.
user=> (map meta (fetch-facts :all))
({:midje/top-level-fact? true, :midje/file "/private/var/folders/bs/57pl2lk08xl2p4001s76y6yh0000gq/T/form-init2898396762993536521.clj", :midje/namespace user, :midje/line 1, :f true, :midje/guid "c90b6fb3c1986d456d538da8d8753a78caa983c8", :midje/source (fact :f 1 => 1)})
user=> (check-facts :f)
= Namespace user
All checks (1) succeeded.
true
user=> (check-facts :inner)
No facts were checked. Is that what you wanted?
nil
Added to trello https://trello.com/c/aPV5YPe9/13-metadata-filtering-not-working-in-groups-275