diff --git a/src/clj/orchestra/spec/test.cljc b/src/clj/orchestra/spec/test.cljc index fa684e9..b4f4f6c 100644 --- a/src/clj/orchestra/spec/test.cljc +++ b/src/clj/orchestra/spec/test.cljc @@ -124,13 +124,13 @@ failure in instrument." (if *instrument-enabled* (let [cargs (when-let [spec (:args fn-spec)] (conform! v :args spec args ::s/args)) - ret (.applyTo ^clojure.lang.IFn f args)] - (when-let [spec (:ret fn-spec)] - (conform! v :ret spec ret ::s/ret)) + ret (.applyTo ^clojure.lang.IFn f args) + cret (when-let [spec (:ret fn-spec)] + (conform! v :ret spec ret ::s/ret))] (when-let [spec (:fn fn-spec)] (if (nil? cargs) (throw (no-args-spec v fn-spec)) - (conform! v :fn spec {:ret ret :args cargs} ::s/fn))) + (conform! v :fn spec {:ret (or cret ret) :args cargs} ::s/fn))) ret) (.applyTo ^clojure.lang.IFn f args))))) diff --git a/src/cljs/orchestra_cljs/spec/test.cljs b/src/cljs/orchestra_cljs/spec/test.cljs index 0f4b1e7..7a10ba2 100644 --- a/src/cljs/orchestra_cljs/spec/test.cljs +++ b/src/cljs/orchestra_cljs/spec/test.cljs @@ -121,13 +121,13 @@ (let [cargs (when (:args fn-spec) (conform! v :args (:args fn-spec) args ::s/args)) ret (binding [*instrument-enabled* true] - (apply' f args))] - (when (:ret fn-spec) - (conform! v :ret (:ret fn-spec) ret ::s/ret)) + (apply' f args)) + cret (when (:ret fn-spec) + (conform! v :ret (:ret fn-spec) ret ::s/ret))] (when-let [spec (:fn fn-spec)] (if (nil? cargs) (throw (no-args-spec v fn-spec)) - (conform! v :fn spec {:ret ret :args cargs} ::s/fn))) + (conform! v :fn spec {:ret (or cret ret) :args cargs} ::s/fn))) ret)) (apply' f args)))] (when-not pure-variadic? diff --git a/test/cljc/orchestra/core_test.cljc b/test/cljc/orchestra/core_test.cljc index fd311b7..bb1e3d4 100644 --- a/test/cljc/orchestra/core_test.cljc +++ b/test/cljc/orchestra/core_test.cljc @@ -192,3 +192,15 @@ (st/instrument) (f)) (use-fixtures :each instrument-fixture) + +(defn-spec conform-ret-into-fn (s/or :error #{:error} + :success string?) + {:fn #(condp = (-> % :ret key) + :success (and (clojure.string/starts-with? (-> % :ret val) "your-") + (clojure.string/ends-with? (-> % :ret val) (-> % :args :string))) + true)} + [string string?] + (str "your-" string)) + +(deftest conform-ret-into-fn-test + (is (conform-ret-into-fn "Hello")))