slagyr / speclj

pronounced "speckle": a TDD/BDD framework for Clojure.
MIT License
459 stars 58 forks source link

Support templates for defining examples #92

Closed hlship closed 9 years ago

hlship commented 10 years ago

I'd like to be able to do the following:

    (do-template [key expected]
                 (it (format "should have the correct value for %s" key)
                     (should= expected (key @asset)

                              :resource-path "META-INF/assets/coffeescript-source.coffee"
                              :asset-path "coffeescript-source.coffee"
                              :content-type "text/javascript"
                              :compiled true
                              :size 160
                              :checksum compiled-coffeescript-checksum)))

That is, easily generate a series of examples (it blocks) from templates. Currently, when I do that:

clojure.lang.Compiler$CompilerException: java.lang.Exception: Oops!  It looks like you tried to add 'nil' to a spec.  That's not allowed., compiling:(/Users/hlship/workspaces/annadale/twixt/spec/io/aviso/twixt_spec.clj:55:48)
                    java.lang.Exception: Oops!  It looks like you tried to add 'nil' to a spec.  That's not allowed.
clojure.lang.Compiler$CompilerException: java.lang.Exception: Oops!  It looks like you tried to add 'nil' to a spec.  That's not allowed., compiling:(/Users/hlship/workspaces/annadale/twixt/spec/io/aviso/twixt_spec.clj:55:48)
                    java.lang.Exception: Oops!  It looks like you tried to add 'nil' to a spec.  That's not allowed.
                                             speclj.components/eval2529/fn                    components.clj:   11
                                           speclj.components/eval2496/fn/G                    components.clj:    3
                                       io.aviso.twixt-spec/eval17951/fn/fn                    twixt_spec.clj:   92
                                          io.aviso.twixt-spec/eval17951/fn                    twixt_spec.clj:   92
                                             io.aviso.twixt-spec/eval17951                    twixt_spec.clj:   57
                                                clojure.lang.Compiler.eval                     Compiler.java: 6703
                                                clojure.lang.Compiler.load                     Compiler.java: 7130
                                             io.aviso.twixt-spec/eval17934  form-init1321303564594210912.clj:    1
                                                clojure.lang.Compiler.eval                     Compiler.java: 6703
                                                clojure.lang.Compiler.eval                     Compiler.java: 6666
                                                         clojure.core/eval                          core.clj: 2927
                                      clojure.main/repl/read-eval-print/fn                          main.clj:  239
                                         clojure.main/repl/read-eval-print                          main.clj:  239
                                                      clojure.main/repl/fn                          main.clj:  257
                                                         clojure.main/repl                          main.clj:  257
                                                clojure.lang.RestFn.invoke                       RestFn.java: 1096
             clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn            interruptible_eval.clj:   56
                                            clojure.lang.AFn.applyToHelper                          AFn.java:  152
                                                  clojure.lang.AFn.applyTo                          AFn.java:  144
                                                        clojure.core/apply                          core.clj:  624
                                               clojure.core/with-bindings*                          core.clj: 1862
                                                clojure.lang.RestFn.invoke                       RestFn.java:  425
                clojure.tools.nrepl.middleware.interruptible-eval/evaluate            interruptible_eval.clj:   41
clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn            interruptible_eval.clj:  171
                                                      clojure.core/comp/fn                          core.clj: 2402
             clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn            interruptible_eval.clj:  138
                                                      clojure.lang.AFn.run                          AFn.java:   22
                         java.util.concurrent.ThreadPoolExecutor.runWorker           ThreadPoolExecutor.java: 1145
                        java.util.concurrent.ThreadPoolExecutor$Worker.run           ThreadPoolExecutor.java:  615
                                                      java.lang.Thread.run                       Thread.java:  724

I'm not quite sure where the nil is coming from.

slagyr commented 9 years ago

I suspect this is just a miscommunication. Speclj describe/context blocks try to be helpful by throwing Exceptions when they contain something that is NOT spec component, like nil. That's why you're getting the error.

You can get the behavior you want. Here's an example:

(defn my-template [expected input](it %28str "checks " input) (should= expected input)))

(describe "specs" (my-template 1 1) (my-template 1 2) )

(run-specs)

Am closing. Please reopen if I misunderstood.