This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-26
Channels
- # admin-announcements (4)
- # beginners (3)
- # boot (78)
- # cider (13)
- # cljs-dev (29)
- # cljs-edn (8)
- # cljsjs (11)
- # cljsrn (15)
- # clojure (81)
- # clojure-beijing (2)
- # clojure-belgium (3)
- # clojure-canada (1)
- # clojure-dusseldorf (8)
- # clojure-greece (6)
- # clojure-russia (40)
- # clojure-sg (1)
- # clojure-uk (59)
- # clojurebridge (1)
- # clojurescript (101)
- # core-logic (1)
- # cursive (3)
- # data-science (1)
- # datomic (60)
- # emacs (4)
- # error-message-catalog (12)
- # funcool (1)
- # hoplon (60)
- # jobs (1)
- # jobs-discuss (40)
- # leiningen (5)
- # liberator (1)
- # mount (22)
- # off-topic (8)
- # om (16)
- # onyx (53)
- # re-frame (11)
- # reagent (2)
- # specter (4)
- # testing (18)
- # untangled (51)
hey guys, i’m wondering how to go about using mock testing files in clojure? what’s the idiomatic way, for example, to read-in a file that’s sitting in spec/path/to/mock.file.json
and test against it, for example?
@lwhorton: yes, I'd use slurp to read the file and data.json or cheshire to parse it, and that's it
but how about the whole relative/absolute file issue? if my spec/some-mod/mock.file.json
is needed for the test, how do I read that so it works across multiple machines/environments?
this is what I’m currently using, but I just don’t know if i’m anywhere close:
(let [cwd (.getAbsolutePath (io/file ""))
res (#’sut/fn (str cwd "/spec/clj/some-module/mock-thing.json"))
for some reason I can’t get at the module I want to test (it throws fn is private
) unless I use #’module/fn
Oh. You can put them in a directory that it's in resources paths, then you can get to it with io/resource and the relative path from that resources directory
I’m really fuzzy on the details of source-paths and resource-paths, I should probably find a blog to read...
wohoo, finally figured it out @nberger, thanks:
(slurp (io/file (io/resource “relative/path/in/resource-paths”)))
i know resource looks up in the resource-path the relative file, and returns the URL