For loop not working inside midje test?

342 views Asked by At

Found some odd behavior in midje, not sure if it's midje related, or due to my misunderstanding of some clojure constructs, but it's puzzling:

Inside a facts statement, a for loop is not getting called:

(ns t1
  (:require [midje.sweet :refer :all ] )
  )

(facts
 (println "ok") ; -- this prints fine
 (for [val '(1 2 3)] (println val)) ; this does not

  (fact "junk"
        (> (.length "aaaaha") 3) => true ))

Thought maybe it had something to do with the for being overwritten in the ns but calling clojure.core/for behaves similarly.

1

There are 1 answers

2
Kyle On BEST ANSWER

clojure.core/for "...yields a lazy sequence..."

You need to realize the sequence to see its side effects.

(doall (for [val '(1 2 3)] (println val)))

I'd suggest using something more appropriate like clojure.core/doseq:

(doseq [val '(1 2 3)] (println val))