0

I have a Leiningen project which uses Midje library for testing. Howerver I am not able to run any tests, in case of lein test I get

java.io.FileNotFoundException: Could not locate midje/sweet__init.class or midje/sweet.clj on classpath

Or alternatively with lein midje test I get

java.io.FileNotFoundException: Could not locate midje/util/ecosystem__init.class or midje/util/ecosystem.clj on classpath

So I guess this is because I have incorrectly defined dev profile with dependencies but I am not sure where the real problem is.

As a bonus, I also cannot get environ working, I am always getting nil which I want to pull some property out of the env map (this might be the same issue as well).

My project.clj

(defproject
  project
  "0.1.0-SNAPSHOT"
  :dependencies
   [[org.clojure/clojure "1.8.0"]
   [environ "1.1.0"]
   ;; other deps, midje is not there
   :repl-options
      {:init-ns mailing.repl}
   :jvm-opts
      ["-server"]
   :plugins
      [[lein-ring "0.8.13"]
       [lein-environ "1.0.0"]
       [lein-ancient "0.5.5"]
       [migratus-lein "0.4.2"]] 
   :ring
     {:handler mailing.handler/app,
   :init mailing.handler/init,
   :destroy mailing.handler/destroy}
   :profiles
      {:uberjar {:omit-source true, :env {:production true}, :aot :all},
       :production
      {:ring {:open-browser? false, :stacktraces? false, :auto-reload? false}},
      {:dev
        {:env 
          {:db-user "user" 
           :db-password "psswd"
           :db-classname "org.postgresql.Driver"
           :db-subprotocol "postgresql"
           :db-subname "//localhost/mailer"}}}
      {:dependencies
[[ring-mock "0.1.5"]
 [ring/ring-devel "1.3.1"]
 [midje "1.6.3"]],
:env {:dev true}}}
  :migratus {
         :store :database
         :migration-dir "migrations"
         :db {
              :classname "org.postgresql.Driver"
              :subprotocol "postgresql"
              :subname "//localhost/mailer"
              :user "usr"
              :password "psswd"}}
;; refer to user and psswd from project
:min-lein-version "2.0.0")
Petr Mensik
  • 26,874
  • 17
  • 90
  • 115

1 Answers1

1

I've not tried this, but the structure doesn't appear quite right. I think it should be something like:

(defproject project "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [environ "1.1.0"]]
  ;; other deps, midje is not there
  :repl-options {:init-ns mailing.repl}
  :jvm-opts ["-server"]
  :plugins [[lein-ring "0.8.13"]
            [lein-environ "1.0.0"]
            [lein-ancient "0.5.5"]
            [migratus-lein "0.4.2"]]
  :ring {:handler mailing.handler/app
         :init mailing.handler/init
         :destroy mailing.handler/destroy}
  :profiles {:uberjar {:omit-source true
                       :env {:production true}
                       :aot :all}
             :production {:ring {:open-browser? false
                                 :stacktraces? false
                                 :auto-reload? false}}
             :dev {:env {:db-user "user"
                         :db-password "psswd"
                         :db-classname "org.postgresql.Driver"
                         :db-subprotocol "postgresql"
                         :db-subname "//localhost/mailer"
                         :dev true}
                   :dependencies [[ring-mock "0.1.5"]
                                  [ring/ring-devel "1.3.1"]
                                  [midje "1.6.3"]]}}
  :migratus {:store :database
             :migration-dir "migrations"
             :db {:classname "org.postgresql.Driver"
                  :subprotocol "postgresql"
                  :subname "//localhost/mailer"
                  :user "usr"
                  :password "psswd"}}

   ;; refer to user and psswd from project
   :min-lein-version "2.0.0")

It looks like your :dependecies block near the top is malformed (no closing ]), and the development dependencies were not actually associated with the :dev profile. I wasn't sure if :migratus belonged with the :dev profile or not, so it's outside of it in the example above.

FWIW, the sample project file in Leiningen's repo is a helpful resource.

John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
  • Tried to follow your advice but error remains the same http://pastebin.com/9uLX038t – Petr Mensik Nov 11 '16 at 20:27
  • Did you try working with the example I gave above? If not, then you may not have fixed the first `:dependencies` block, which is also a problem. Also, can you get it down to a smaller example? If so, I can take a look a little later and help. My best advice outside of that would be to try creating a new `defproject` block with the bare minimum, and see if you can get something running and then build up from there. – John Szakmeister Nov 11 '16 at 21:52
  • Yes, it's the resource I looked into even before I asked here and I played with the setup for couple of hours. That's why I went to SO because I really don't know how to convince Leiningen that the Midje is really there. But I'll try with less complicated setup and I'll see, thanks. – Petr Mensik Nov 11 '16 at 22:13
  • Bah, I messed up the `:dev` dependencies too. I updated the `defproject` with it in the correct location this time, and changed the formatting so it's easier to see where things are located. Hope it helps and fixes your issue. – John Szakmeister Nov 12 '16 at 00:33
  • Thank you, your changes have really worked for me at the end (I had to place lein-midje to the plugins as well). – Petr Mensik Nov 13 '16 at 22:22
  • Just a bonus question if I may :) I noticed that when I run `lein ring server` that environ from `dev` profile is not set in the running application so the correct way is to somehow merge those profiles? Or is there any other recommended way of doing this? It works if run `(env :db-name)` from the REPL – Petr Mensik Nov 13 '16 at 22:25
  • I believe you can get what you want by running `lein with-proflie dev ring server`, though I expect it to be active by default. :-/ – John Szakmeister Nov 13 '16 at 23:22
  • That's actually what I've tried as well :) but with no success :-/ – Petr Mensik Nov 14 '16 at 09:19