naem refactorings
This commit is contained in:
parent
c0e7925039
commit
e8930ced06
7 changed files with 22 additions and 14 deletions
|
@ -29,7 +29,7 @@
|
||||||
(defmacro defdatatest [n & body]
|
(defmacro defdatatest [n & body]
|
||||||
(when ct/*load-tests*
|
(when ct/*load-tests*
|
||||||
(let [namespaced-test-key# (keyword (str *ns*) (name n))
|
(let [namespaced-test-key# (keyword (str *ns*) (name n))
|
||||||
file-prefix# (fl/data-file-prefix namespaced-test-key#)]
|
file-prefix# (fl/data-test-spec-file-prefix namespaced-test-key#)]
|
||||||
`(def ~(vary-meta n assoc
|
`(def ~(vary-meta n assoc
|
||||||
:test `(fn []
|
:test `(fn []
|
||||||
(let [testdata# (fl/load-test-data ~file-prefix#)
|
(let [testdata# (fl/load-test-data ~file-prefix#)
|
||||||
|
|
|
@ -25,22 +25,26 @@
|
||||||
{:input s/Any
|
{:input s/Any
|
||||||
:expectation s/Any})
|
:expectation s/Any})
|
||||||
|
|
||||||
(s/defn read-data :- TestDataSpec
|
(s/defn read-test-data-spec :- TestDataSpec
|
||||||
[resource-url :- s/Str]
|
[resource-url :- s/Str]
|
||||||
(aero/read-config resource-url))
|
(aero/read-config resource-url))
|
||||||
|
|
||||||
(s/defn data-file-prefix :- s/Str
|
(s/defn data-test-spec-file-prefix :- s/Str
|
||||||
[name-key :- s/Keyword]
|
[name-key :- s/Keyword]
|
||||||
(str/replace
|
(str/replace
|
||||||
(str/replace (str (namespace name-key) "/" (name name-key))
|
(str/replace (str (namespace name-key) "/" (name name-key))
|
||||||
#"-" "_")
|
#"-" "_")
|
||||||
#"\." "/"))
|
#"\." "/"))
|
||||||
|
|
||||||
|
(s/defn find-data-spec-files :- [s/Any]
|
||||||
|
[data-test-spec-file-prefix :- s/Str]
|
||||||
|
(.listFiles (io/resource (str data-test-spec-file-prefix "*.edn"))))
|
||||||
|
|
||||||
(s/defn load-test-data
|
(s/defn load-test-data
|
||||||
[file-prefix :- s/Str]
|
[file-prefix :- s/Str]
|
||||||
(let [file-path (str file-prefix ".edn")]
|
(let [file-path (str file-prefix ".edn")]
|
||||||
(try
|
(try
|
||||||
(read-data (io/resource file-path))
|
(read-test-data-spec (io/resource file-path))
|
||||||
(catch IllegalArgumentException e
|
(catch IllegalArgumentException e
|
||||||
(throw (ex-info (str "Could not find test spec on " file-path)
|
(throw (ex-info (str "Could not find test spec on " file-path)
|
||||||
{:message "Could not find test spec"
|
{:message "Could not find test spec"
|
||||||
|
|
|
@ -48,9 +48,9 @@
|
||||||
(extend-type TestRunner
|
(extend-type TestRunner
|
||||||
RunTest
|
RunTest
|
||||||
(name-prefix [_]
|
(name-prefix [_]
|
||||||
(fl/data-file-prefix (:name _)))
|
(fl/data-test-spec-file-prefix (:name _)))
|
||||||
(run-tests [_]
|
(run-tests [_]
|
||||||
(let [testdata (fl/load-test-data (fl/data-file-prefix (:name _)))
|
(let [testdata (fl/load-test-data (fl/data-test-spec-file-prefix (:name _)))
|
||||||
{:keys [input expectation]} testdata]
|
{:keys [input expectation]} testdata]
|
||||||
(data-test _ input expectation))))
|
(data-test _ input expectation))))
|
||||||
|
|
||||||
|
|
1
test/resources/data_test/file_loader_test/test_it.1.edn
Normal file
1
test/resources/data_test/file_loader_test/test_it.1.edn
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{:test "data"}
|
1
test/resources/data_test/file_loader_test/test_it.99.edn
Normal file
1
test/resources/data_test/file_loader_test/test_it.99.edn
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{:test "data"}
|
|
@ -20,21 +20,23 @@
|
||||||
[schema.core :as s]
|
[schema.core :as s]
|
||||||
[data-test.file-loader :as sut]))
|
[data-test.file-loader :as sut]))
|
||||||
|
|
||||||
(deftest should-read-data
|
(deftest should-read-test-data-spec
|
||||||
(is (= {:simple "test"}
|
(is (= {:simple "test"}
|
||||||
(sut/read-data (io/resource "simple_aero.edn"))))
|
(sut/read-test-data-spec (io/resource "simple_aero.edn"))))
|
||||||
(is (= {:to-be-refernced "ref-test", :key1 "ref-test", :key2 "ref-test"}
|
(is (= {:to-be-refernced "ref-test", :key1 "ref-test", :key2 "ref-test"}
|
||||||
(sut/read-data (io/resource "tagged_aero.edn"))))
|
(sut/read-test-data-spec (io/resource "tagged_aero.edn"))))
|
||||||
)
|
)
|
||||||
|
|
||||||
(deftest should-calculate-data-file-prefix
|
(deftest should-calculate-data-test-spec-file-prefix
|
||||||
(is (= "data_test/file_loader_test/test_it"
|
(is (= "data_test/file_loader_test/test_it"
|
||||||
(sut/data-file-prefix ::test-it))))
|
(sut/data-test-spec-file-prefix ::test-it))))
|
||||||
|
|
||||||
(deftest should-load-data
|
(deftest should-load-data
|
||||||
(is (= {:test "data"}
|
(is (= {:test "data"}
|
||||||
(sut/load-test-data (sut/data-file-prefix ::test-it)))))
|
(sut/load-test-data (sut/data-test-spec-file-prefix ::test-it)))))
|
||||||
|
|
||||||
(deftest should-throw-exception
|
(deftest should-throw-exception
|
||||||
(is (thrown? RuntimeException
|
(is (thrown? RuntimeException
|
||||||
(sut/load-test-data (sut/data-file-prefix ::not-existing)))))
|
(sut/load-test-data (sut/data-test-spec-file-prefix ::not-existing)))))
|
||||||
|
|
||||||
|
(sut/find-data-spec-files (sut/data-test-spec-file-prefix ::test-it))
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
; -------------------- explicit version ------------------
|
; -------------------- explicit version ------------------
|
||||||
(deftest should-test-with-data-explicit-version
|
(deftest should-test-with-data-explicit-version
|
||||||
(let [testdata (fl/read-data (io/resource "data_test_test/should-test-with-data-explicit-version.edn"))
|
(let [testdata (fl/read-test-data-spec (io/resource "data_test_test/should-test-with-data-explicit-version.edn"))
|
||||||
{:keys [input expectation]} testdata]
|
{:keys [input expectation]} testdata]
|
||||||
(is (= expectation
|
(is (= expectation
|
||||||
input))))
|
input))))
|
||||||
|
|
Loading…
Reference in a new issue