Search code examples
importclojurenamespacesmidje

I cannot run tests in clojure/midje


I run tests with:

lein midje :autotest

And I get error:

Exception in thread "main" java.lang.Exception: No namespace: sprint-is.json-export found

File is in: sprint-is/src/sprint_is/json_export.clj

It contains code:

(ns sprint-is.json-export)
(require [[noir.response :as response]])
(defn serialize [value] (response/json value))

It throws this error even when I don't have no test file. When I create test file, I get similar error:

No namespace: sprint-is.test.json-export found

Test is in: sprint-is/test/sprint_is/json_export.clj

And contains:

(ns sprint-is.test.json-export
    (:require [sprint-is.json-export :as json-export]))

(fact "module can serialize scalar values"
    (json-export/serialize 123) => 123)

When I try to import it from REPL, it cannot find the namespaces too. I tried to rename file, move files, rename directories, remove ns (it compiles but it doesn't work), asked on Clojure IRC. I compared the code with other projects (including those working on my computer) and it seems same.

Source code is here: https://bitbucket.org/jiriknesl/sprintis


Solution

  • You have a compilation error in one of your namespaces, I suspect sprint-is.json-export

    On bitbucket, you have this:

    (ns sprint-is.json-export)
    
    (require [[noir.response :as response]])
    
    (defn serialize [value] (response/json value))
    

    which won't compile because noir.response and response are not defined.

    you should have:

    (ns sprint-is.json-export
       (:require [noir.response :as response]))
    
    (defn serialize [value] (response/json value))
    

    If you insist on using require outside of the ns macro, you can do the following, but be aware this is not idiomatic usage.

    (ns sprint-is.json-export)
    
    (require '[noir.response :as response])
    
    (defn serialize [value] (response/json value))