How can I use my specs for their intended purposes if they are in a separate namespace?

后端 未结 1 1514
遇见更好的自我
遇见更好的自我 2021-02-05 03:45

One of the examples in the clojure.spec Guide is a simple option-parsing spec:

(require \'[clojure.spec :as s])

(s/def ::config
  (s/* (s/cat :prop string?
              


        
1条回答
  •  别那么骄傲
    2021-02-05 04:36

    This question demonstrates an important distinction between specs used within an application and specs used to test the application.

    Specs used within the app to conform or validate input — like :example.core/config here — are part of the application code. They may be in the same file where they are used or in a separate file. In the latter case, the application code must :require the specs, just like any other code.

    Specs used as tests are loaded after the code they specify. These are your fdefs and generators. You can put these in a separate namespace from the code — even in a separate directory, not packaged with your application — and they will :require the code.

    It's possible you have some predicates or utility functions that are used by both kinds of specs. These would go in a separate namespace all of their own.

    0 讨论(0)
提交回复
热议问题