two questions about using midje

28 views
Skip to first unread message

Roelof Wobben

unread,
Oct 21, 2014, 3:15:21 PM10/21/14
to mi...@googlegroups.com
Hello,

I new to Clojure and midje.
I follow the iloveponies github course.

Now I wonder if I could do this :

1) Test only 1 function instead of the whole namespace.
2) See which test is failing instead of a message that a test is failing.

if so, how can I achieve both ?

Roelof

Brian Marick

unread,
Oct 26, 2014, 11:15:09 PM10/26/14
to mi...@googlegroups.com

> 1) Test only 1 function instead of the whole namespace.

You can use metadata to run a subset of facts in a namespace. See https://github.com/marick/Midje/wiki/Using-metadata-to-filter-facts

I predict that using `autotest` will be faster for you. https://github.com/marick/Midje/wiki/Autotest

> 2) See which test is failing instead of a message that a test is failing.

Facts are compiled into functions that have their original source attached to them. Things aren't set up to make it easy to work directly with that metadata, but you can. For example:

user=> (fact "my favorite fact" 1 => 2)

FAIL "my favorite fact" at (form-init7970193255801025451.clj:2)
Expected: 2
Actual: 1
false
user=> (def f (first (fetch-facts "favorite")))
#'user/f
user=> (keys (meta f))
(:midje/top-level-fact? :midje/file :midje/description
:midje/namespace :midje/line :midje/name :midje/guid
:midje/source)
user=> (pprint (:midje/source (meta f)))
(fact "my favorite fact" 1 => 2)
nil


--------
Latest book: /Functional Programming for the Object-Oriented Programmer/
https://leanpub.com/fp-oo

Reply all
Reply to author
Forward
0 new messages