(ns my-test
(:require
[fulcro-spec.core :refer [specification when-mocking provided assertions]]
[clojure.test :refer [deftest]]
...))
(defn f [x] 900)
(defn g [y] (+ y (f y)))
(deftest my-test
(when-mocking
(f x) => 22
(assertions
"mocking works"
(g 9) => 31)))The specification macro is a convenient alternative to deftest that provides enhanced reporting
and metadata support:
;; Basic usage
(specification "My feature works correctly"
(assertions
"addition works"
(+ 1 2) => 3))
;; With selector keywords for test filtering (e.g., :focus)
(specification "Debug this test" :focus
(assertions
(+ 1 2) => 3))
;; With custom metadata map for advanced test organization
(specification {:integration true :slow true} "Database integration test"
(assertions
(db/query ...) => ...))
;; Combining metadata map with selector keywords
(specification {:integration true} "Critical integration test" :focus
(assertions
(critical-operation) => expected-result))The metadata map (when provided) must appear before the test name string. Selector keywords
(like :focus) follow the test name and are automatically converted to metadata. Both metadata
sources are merged, allowing test runners to filter tests by any metadata key.
It is common to want to run tests in the REPL, but the output of the default runner leaves a lot to be desired. If you’re using IntelliJ you can now add something like this to your REPL commands (and hook it to a keyboard shortcut) for a much better testing experience:
Run Tests with a :focus metadata marker (selector):
(in-ns (.getName *ns*))
(require 'fulcro-spec.reporters.repl)
(fulcro-spec.reporters.repl/run-tests #(:focus (meta %)))Run all tests:
(in-ns (.getName *ns*))
(require 'fulcro-spec.reporters.repl)
(fulcro-spec.reporters.repl/run-tests)See the docs for more details.