热修复:“警告:任何?已经引用:#'clojure.core / any?在命名空间:leiningen.midje中,被替换为:#'leiningen.midje / any?”。

时间:2019-05-28 14:58:46

标签: clojure leiningen compojure midje

我尝试使用midje框架在leiningen的compojure模板(lein new compojure financeiro)中运行测试,并收到警告:

lein midje
WARNING: any? already refers to: #'clojure.core/any? in namespace: leiningen.midje, being replaced by: #'leiningen.midje/any?
nil
All checks (3) succeeded.

我的测试代码handler_test.clj

(ns financeiro.handler-test
  (:require
    ; [clojure.test :refer :all]
    [midje.sweet :refer :all]
    [ring.mock.request :as mock]
    [financeiro.handler :refer :all]))

; (deftest test-app
;   (testing "main route"
;     (let [response (app (mock/request :get "/"))]
;       (is (= (:status response) 200))
;       (is (= (:body response) "Hello World"))))

;   (testing "not-found route"
;     (let [response (app (mock/request :get "/invalid"))]
;       (is (= (:status response) 404)))))

(facts "'Hello World' main route"
  (fact "response status is 200"
    (let [response (app (mock/request :get "/"))]
      (:status response)=> 200))

  (fact "body text is 'Hello World'"
    (let [response (app (mock/request :get "/"))]
      (:body response)=> "Hello World")))

(facts "not-found route"
  (fact "response status is 404"
    (let [response(app (mock/request :get "/invalid"))]
      (:status response)=> 404)))

我的项目文件project.clj

(defproject financeiro "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :min-lein-version "2.0.0"
  :dependencies [
    [org.clojure/clojure "1.10.0"]
    [compojure "1.6.1"]
    [ring/ring-defaults "0.3.2"]
  ]
  :plugins [
    [lein-ring "0.12.5"]
  ]
  :ring {
    :handler financeiro.handler/app
  }
  :profiles {
    :dev {
      :dependencies [
        [javax.servlet/servlet-api "2.5"]
        [ring/ring-mock "0.3.2"]
        [midje "1.9.8"]
      ]
      :plugins [
        [lein-midje "3.2.1"]
      ]
    }
  }
)

当我使用clojure.testlein test)运行默认测试时,我没有收到警告,但是当我使用midje.sweetlein midje)运行时,我收到了有关< strong>'namespace:leiningen.midje'和'replace#'cl​​ojure.core / any?到#'leiningen.midje / any?',我在网上寻找解决方案,但没有找到此特定警告(leiningen / compojure / midje),我是Clojure和Midje的初学者。我正在学习。我可以在哪个文件中替换此命名空间?有消除此警告的简单解决方案吗?还是这是框架midje中的错误?

这不会打扰测试的执行,但是每次运行测试时都会看到此消息很烦人。

注意:我也尝试过{@ {1}}的早期版本的midje,但未成功!

1 个答案:

答案 0 :(得分:3)

此特定问题已解决in this Pull Request

对于一般情况,您可以通过排除(=取消引用)您要从clojure.core之外的另一个命名空间中删除的符号来摆脱此警告(当它来自代码时)。

以下是来自不同上下文的示例:

警告

(ns urbest.apheleia.system.typography
  (:require [garden.units :refer [rem]]))
WARNING: rem already refers to: #'clojure.core/rem in namespace: urbest.apheleia.system.typography, being replaced by: #'garden.units/rem

不再警告

(ns urbest.apheleia.system.typography
  (:refer-clojure :exclude [rem])
  (:require [garden.units :refer [rem]]))