Skip to content

Commit

Permalink
Manually reverted 42dbd8d (PR slagyr#164).
Browse files Browse the repository at this point in the history
Unfortunately, this commit hampered running specs in ClojureScript
(`lein cljs`). The high-level descriptions were being found (and
reported) but none of their contained characteristics or nested contexts
were executed.

As a result of this revert, the new 'focus'-related features are
somewhat hampered. Specifically, a context that is nested within a
focused context is not being executed as expected. I hope to resolve
this in a subsequent commit.
  • Loading branch information
mdwhatcott committed Mar 18, 2022
1 parent fa386c9 commit 2dadd3c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 104 deletions.
91 changes: 42 additions & 49 deletions spec/speclj/core_spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -136,62 +136,65 @@
(let [widget (atom 5)
call-count (atom 0)]

(around-all [context]
(swap! call-count inc)
(binding [*gewgaw* (swap! widget inc)]
(context)))
[
(around-all [context]
(swap! call-count inc)
(binding [*gewgaw* (swap! widget inc)]
(context)))

(it "executes before the specs"
(should= 6 @widget))
(it "executes before the specs"
(should= 6 @widget))

(it "executes around the specs"
(should= 6 *gewgaw*))
(it "executes around the specs"
(should= 6 *gewgaw*))

(it "only executes once"
(should= 1 @call-count))
(it "only executes once"
(should= 1 @call-count))

(context "nested"
(around-all [context]
(swap! call-count inc)
(swap! widget #(/ % 2))
(context))
(context "nested"
(around-all [context]
(swap! call-count inc)
(swap! widget #(/ % 2))
(context))

(around-all [context]
(swap! call-count inc)
(swap! widget #(- % 2))
(context))
(around-all [context]
(swap! call-count inc)
(swap! widget #(- % 2))
(context))

(it "executes in the order in which they are defined"
(should= 1 @widget))
(it "executes in the order in which they are defined"
(should= 1 @widget))

(it "and still only execute once"
(should= 3 @call-count)))))
(it "and still only execute once"
(should= 3 @call-count)))]))

(describe "with before-alls"
(let [widget (atom 6)]
(around-all [context]
(swap! widget #(- % 2))
(context))
[
(around-all [context]
(swap! widget #(- % 2))
(context))

(before-all
(swap! widget #(/ % 2)))
(before-all
(swap! widget #(/ % 2)))

(it "executes after before-alls regardless of definition order"
(should= 1 @widget))))
(it "executes after before-alls regardless of definition order"
(should= 1 @widget))]))

(describe "with withs"
(let [widget (atom 6)]
(describe "with after-alls"
(after-all
(swap! widget #(/ % 2)))
[
(describe "with after-alls"
(after-all
(swap! widget #(/ % 2)))

(around-all [context]
(context))
(swap! widget #(- % 2)))
(around-all [context]
(context))
(swap! widget #(- % 2)))

(describe "previous after-all and around-all forms"
(it "executes before after-alls regardless of definition order"
(should= 2 @widget))))
(describe "previous after-all and around-all forms"
(it "executes before after-alls regardless of definition order"
(should= 2 @widget)))])

(describe "with with-alls"
(with-all with-all-val 1)
Expand Down Expand Up @@ -355,15 +358,5 @@
(it "has not been reset and deref'ed"
(should= 1 @non-lazy-with-all-calls)))

(describe "Nesting components inside let"
(let [a (atom 0)]
(it "first one runs"
(swap! a inc))
(it "second one runs"
(swap! a inc))
(it "third one runs"
(swap! a inc)
(should= 3 @a))))

;(run-specs :tags ["two"])
(run-specs)
41 changes: 1 addition & 40 deletions src/speclj/components.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(ns speclj.components
(:require [speclj.config]))
(ns speclj.components)

(defprotocol SpecComponent
(install [this description]))
Expand Down Expand Up @@ -196,41 +195,3 @@

(defn new-tag [name]
(Tag. name))

(defn pre-install [x]
(when #?(:clj (bound? #'speclj.config/*parent-description*) :cljs speclj.config/*runner*)
(install x speclj.config/*parent-description*))
x)

(def install-new-description
(comp pre-install new-description))

(def install-new-characteristic
(comp pre-install new-characteristic))

(def install-new-tag
(comp pre-install new-tag))

(def install-new-with
(comp pre-install new-with))

(def install-new-with-all
(comp pre-install new-with-all))

(def install-new-before
(comp pre-install new-before))

(def install-new-before-all
(comp pre-install new-before-all))

(def install-new-after
(comp pre-install new-after))

(def install-new-after-all
(comp pre-install new-after-all))

(def install-new-around
(comp pre-install new-around))

(def install-new-around-all
(comp pre-install new-around-all))
31 changes: 16 additions & 15 deletions src/speclj/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@

(defmacro ^:no-doc help-it [name focused? & body]
(if (seq body)
`(speclj.components/install-new-characteristic ~name (fn [] ~@body) ~focused?)
`(speclj.components/install-new-characteristic ~name (fn [] (pending)) ~focused?)))
`(speclj.components/new-characteristic ~name (fn [] ~@body) ~focused?)
`(speclj.components/new-characteristic ~name (fn [] (pending)) ~focused?)))

(defmacro ^:no-doc help-describe [name focused? & components]
`(let [description# (speclj.components/install-new-description ~name ~focused? ~(clojure.core/name (.name *ns*)))]
`(let [description# (speclj.components/new-description ~name ~focused? ~(clojure.core/name (.name *ns*)))]
(binding [speclj.config/*parent-description* description#]
; MDM - use a vector below - cljs generates a warning because def/declares don't eval immediately
(vector ~@components))
(doseq [component# (vector ~@components)]
(speclj.components/install component# description#)))
(when-not (if-cljs
speclj.config/*parent-description*
(bound? #'speclj.config/*parent-description*))
Expand Down Expand Up @@ -109,13 +110,13 @@
"Declares a function that is invoked before each characteristic in the containing describe scope is evaluated. The body
may consist of any forms, presumably ones that perform side effects."
[& body]
`(speclj.components/install-new-before (fn [] ~@body)))
`(speclj.components/new-before (fn [] ~@body)))

(defmacro after
"Declares a function that is invoked after each characteristic in the containing describe scope is evaluated. The body
may consist of any forms, presumably ones that perform side effects."
[& body]
`(speclj.components/install-new-after (fn [] ~@body)))
`(speclj.components/new-after (fn [] ~@body)))

(defmacro around
"Declares a function that will be invoked around each characteristic of the containing describe scope.
Expand All @@ -127,24 +128,24 @@
(around [it] (try (it) (finally :clean-up)))"
[binding & body]
`(speclj.components/install-new-around (fn ~binding ~@body)))
`(speclj.components/new-around (fn ~binding ~@body)))

(defmacro before-all
"Declares a function that is invoked once before any characteristic in the containing describe scope is evaluated. The
body may consist of any forms, presumably ones that perform side effects."
[& body]
`(speclj.components/install-new-before-all (fn [] ~@body)))
`(speclj.components/new-before-all (fn [] ~@body)))

(defmacro after-all
"Declares a function that is invoked once after all the characteristics in the containing describe scope have been
evaluated. The body may consist of any forms, presumably ones that perform side effects."
[& body]
`(speclj.components/install-new-after-all (fn [] ~@body)))
`(speclj.components/new-after-all (fn [] ~@body)))

(defmacro around-all
"Declares a function that is invoked once around all characteristics of the containing describe scope."
[context & body]
`(speclj.components/install-new-around-all (fn ~context ~@body)))
`(speclj.components/new-around-all (fn ~context ~@body)))

(def cljs-munge
#?(:clj
Expand Down Expand Up @@ -173,7 +174,7 @@
(with meaning 42)
(it \"knows the meaning of life\" (should= @meaning (the-meaning-of :life)))"
[name & body]
(-make-with name body `speclj.components/install-new-with false))
(-make-with name body `speclj.components/new-with false))

(defmacro with!
"Declares a reference-able symbol that will be evaluated immediately and reset once per characteristic of the containing
Expand All @@ -183,7 +184,7 @@
(with! my-with! (swap! my-num inc))
(it \"increments my-num before being accessed\" (should= 1 @my-num) (should= 2 @my-with!))"
[name & body]
(-make-with name body `speclj.components/install-new-with true))
(-make-with name body `speclj.components/new-with true))

(defmacro with-all
"Declares a reference-able symbol that will be lazily evaluated once per context. The body may contain any forms,
Expand All @@ -192,7 +193,7 @@
(with-all meaning 42)
(it \"knows the meaning of life\" (should= @meaning (the-meaning-of :life)))"
[name & body]
(-make-with name body `speclj.components/install-new-with-all false))
(-make-with name body `speclj.components/new-with-all false))

(defmacro with-all!
"Declares a reference-able symbol that will be immediately evaluated once per context. The body may contain any forms,
Expand All @@ -207,7 +208,7 @@
(should= 1 @my-num)
(should= 2 @my-with!))"
[name & body]
(-make-with name body `speclj.components/install-new-with-all true))
(-make-with name body `speclj.components/new-with-all true))

(defmacro ^:no-doc -to-s [thing]
`(if (nil? ~thing) "nil" (pr-str ~thing)))
Expand Down Expand Up @@ -589,7 +590,7 @@ There are three options for passing different kinds of predicates:
(tags :one :two)"
[& values]
(let [tag-kws (mapv keyword values)]
`(mapv speclj.components/install-new-tag ~tag-kws)))
`(mapv speclj.components/new-tag ~tag-kws)))

(defmacro with-stubs
"Add this to describe/context blocks that use stubs. It will setup a clean recording environment."
Expand Down

0 comments on commit 2dadd3c

Please sign in to comment.