naem refactorings

This commit is contained in:
jem 2019-05-24 14:54:18 +02:00
parent c0e7925039
commit e8930ced06
7 changed files with 22 additions and 14 deletions

View file

@ -29,7 +29,7 @@
(defmacro defdatatest [n & body]
(when ct/*load-tests*
(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
:test `(fn []
(let [testdata# (fl/load-test-data ~file-prefix#)

View file

@ -25,22 +25,26 @@
{:input s/Any
:expectation s/Any})
(s/defn read-data :- TestDataSpec
(s/defn read-test-data-spec :- TestDataSpec
[resource-url :- s/Str]
(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]
(str/replace
(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
[file-prefix :- s/Str]
(let [file-path (str file-prefix ".edn")]
(try
(read-data (io/resource file-path))
(read-test-data-spec (io/resource file-path))
(catch IllegalArgumentException e
(throw (ex-info (str "Could not find test spec on " file-path)
{:message "Could not find test spec"

View file

@ -48,9 +48,9 @@
(extend-type TestRunner
RunTest
(name-prefix [_]
(fl/data-file-prefix (:name _)))
(fl/data-test-spec-file-prefix (:name _)))
(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]
(data-test _ input expectation))))

View file

@ -0,0 +1 @@
{:test "data"}

View file

@ -0,0 +1 @@
{:test "data"}

View file

@ -20,21 +20,23 @@
[schema.core :as s]
[data-test.file-loader :as sut]))
(deftest should-read-data
(deftest should-read-test-data-spec
(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"}
(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"
(sut/data-file-prefix ::test-it))))
(sut/data-test-spec-file-prefix ::test-it))))
(deftest should-load-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
(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))

View file

@ -24,7 +24,7 @@
; -------------------- 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]
(is (= expectation
input))))