jakemcc / test-refresh

Refreshes and reruns clojure.tests in your project.
393 stars 28 forks source link

Specs are not reloaded when run through compojure-api #70

Closed ingesolvoll closed 7 years ago

ingesolvoll commented 7 years ago

With the project defined below, changes to my spec does not affect outcome of tests. You could change from string? to keyword? and test still passes.

When running specs directly on functions and instrumenting them, refreshing works. The issue only applies to specs like the ones below, referenced through compojure-api.

I realize this is likely to be an issue with either my code or with compojure-api. So please disregard or close if you think this is outside the scope of lein-test-refresh.

project.clj

(defproject proj "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.9.0-alpha17"]
                 [metosin/compojure-api "2.0.0-alpha7"]
                 [metosin/spec-tools "0.3.0"]
                 [ring/ring-mock "0.3.1"]
                 [ring/ring-json "0.5.0-beta1"]]
  :plugins [[com.jakemccrary/lein-test-refresh "0.20.0"]]
  :source-paths ["src"]
  :test-paths ["test"]
)

Source

(ns dings.core
  (:require [clojure.spec.alpha :as s]
            [compojure.api.sweet :as sweet :refer [api context GET POST PUT]]
            [ring.util.http-response :as response]
            [spec-tools.spec :as spec]))

(s/def ::fmu-list (s/coll-of string?))

(defn api-routes []
  (api
    {:coercion :spec}
    (context "/" []
      (GET "/allfmus" []
        :summary "All of them"
        :return ::fmu-list
        (response/ok ["one" "two"])))))

Test source

(ns dings.core-test
  (:require [clojure.test :refer :all]
            [dings.core :as core]
            [ring.mock.request :as mock]
            [ring.middleware.json :refer [wrap-json-response]]
            [cheshire.core :as cheshire]))

(defn parse-body [body]
  (cheshire/parse-string (slurp body) true))

(defn routes []
  (-> (core/api-routes)
      wrap-json-response))

(deftest fmus
  (testing "All FMUS work and correspond to spec"
    (let [response ((routes) (mock/request :get "/allfmus"))]
      (is (= ["one" "two"] (-> response :body parse-body))))))
ingesolvoll commented 7 years ago

And now the problem went away in my local project. I don't see why, but I'm pretty sure I'm messing this up myself. Closing, will report back if I find new info.

jakemcc commented 7 years ago

@ingesolvoll Well, glad to hear the problem went away 😄 . Thanks for opening.