ghostwheel

Hassle-free clojure.spec, automatic generative testing, side effect detection, and evaluation tracing for Clojure(-Script) – https://github.com/gnl/ghostwheel
Sen 2018-09-01T02:59:07.000100Z

Can I use clojure.spec.gen.alpha 's together with Ghostwheel? In my particular case I cannot figure out how to create a spec that would generate tests for only two possible strings, for example something like this:

(>defn my-fun 
  [either-one]
  [(gen/elements ["good" "bad"])
  => string?]
  (str "this is " either-one "code"))
Expected generated input would either string "good" or "bad" for every case. How to do this? Please, help 🙏

Sen 2018-09-01T03:04:05.000100Z

I tried many approaches, including | (s/or #(= % "good") #(= % "bad")), (s/alt :g "good" :b "bad"), nothing worked, generator cannot generate tests with such specs

Sen 2018-09-01T03:04:58.000100Z

Though this works with clojure.spec.gen, at least in repl

gnl 2018-09-01T10:42:52.000100Z

@armikhalev This doesn't work, you're passing a generator where you need a spec. You want to define the generator with the spec:

(s/def ::some-spec (s/with-gen <spec> <generator-fn>)
(>defn my-fun
  [either-one]
  [::some-spec => string?]
  ...)
Although in this particular case it would be easier to simply let the standard generators handle it:
(>defn my-fun
  [either-one]
  [#{"good" "bad"} => string?]
  ...)
I recommend reading through the whole Spec guide to clear this stuff up: https://clojure.org/guides/spec It's not too long and will answer all of these questions.

gnl 2018-09-01T11:07:18.000100Z

P.S. If you want to see what Ghostwheel does exactly in a particular situation and how it desugars to standard spec, you can just do (macroexpand-1 '(>defn ....)) in the REPL.

Sen 2018-09-02T00:12:40.000100Z

Thank you, #{"good" "bad"} was exactly what I needed! Didn't realize that I can use this as a spec, I'm still too new to Clojure and Spec.