This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-17
Channels
- # bangalore-clj (2)
- # beginners (51)
- # boot (20)
- # cider (14)
- # clara (1)
- # cljs-dev (14)
- # cljsrn (50)
- # clojure (140)
- # clojure-dev (5)
- # clojure-france (1)
- # clojure-gamedev (3)
- # clojure-italy (4)
- # clojure-poland (3)
- # clojure-russia (8)
- # clojure-sg (1)
- # clojure-spec (64)
- # clojure-uk (51)
- # clojurescript (54)
- # core-typed (1)
- # data-science (2)
- # datomic (61)
- # docker (1)
- # emacs (6)
- # events (1)
- # graphql (1)
- # hoplon (14)
- # leiningen (8)
- # luminus (3)
- # mount (6)
- # off-topic (18)
- # om (17)
- # parinfer (34)
- # pedestal (47)
- # play-clj (1)
- # protorepl (1)
- # re-frame (56)
- # reagent (11)
- # ring-swagger (5)
- # rum (6)
- # sql (1)
- # uncomplicate (2)
- # vim (3)
- # yada (31)
@lwhorton I don't think you can spec protocols, the recommendation I got at the time was to create a regular function in front of the protocol function and spec that
congratulations by the way. i hope you have a heck of a time with the kiddo. I’‘ll certainly miss The REPL.
I won't be gone for too long 🙂
yea .. that’s what I’m rolling with. I probably wasn’t clear, but in my question I’m trying to address the issue with trying to test.check multiple “regular functions in front of the protocol function” for each possible argument type
as @seancorfield mentions, they’re open for extension so you can’t cover every base. that being said, i’m only trying to cover my particular bases.
Worth remembering also that you can spec that the value your wrapping fn receives satisfies?
the protocol. You’ll need to write a custom generator to generate conforming values for each of the implementations you care about though. You don’t get that for free like you do with multi-spec.
This said if your implementations had a common construction interface… e.g. they all took a string as a single argument to their constructor, you could easily write a dynamic generator by inspecting the protocol i.e. by using (keys (:impls foo.bar/Protocol))
then mapping the implementation classes to constructors/generators
I have a fn I'd like to spec but am currently omitting spec'ing one particular argument, which I'm expecting to be an HTML5 File/Blob
@samueldev I’ll add that to the README
A user has also reported a issue on CLJS 1.9.671 (I had been testing on CLJS 1.9.542). Just FYI: https://github.com/bhb/expound/issues/3
@bbrinck using the lib and converted all my spec explains to yours this morning; quite pleased 🙂
its aim seems to be to output developer-friendly error messages; have you considered the use case of going all the way and having it output non-developer-friendly error messages, that can be presented to an end-user?
for example if I'm doing some simple validation on a POST route in my API to create an entity, and they omit a required key, an output-string provided along the lines of "Missing required key: _____"
as it stands now, I'm using regular spec explains and iterating over the problems
and generating these strings
(with some hard-coded mappings from something like a str?
predicate failing --> a string being generated along the lines of "Value provided for key ____ must be a string."
this is something I've considered lib-ifying for my own sake but could instead PR it into expound perhaps, if you see value in it
Yes, in the future, I want to have good defaults for a number of contexts: test failures, REPL, end-user, etc
That won’t replace the current error message, but it’ll either be another namespace or perhaps some way to configure expound
But more generally, I want to extract out a set of helper functions that work on clojure.spec.problem
s such that you can trivially build your own custom string representation without dealing with all the details of spec
That way, if you don’t like the default “user-facing” error message, you can peek underneath and see how its built and build your own.
@samueldev If you want to create a GH issue with an example of a spec, a value, and the error string you’d like to see for a user-facing error, that would be very helpful!
for a spec that can potentially generate huge values (like giant nested maps with long keywords), what is the most efficient way to get a small values (for playing around with at the repl)
for some reason, my spec errors are printed without newline, which makes them completely unreadable:
:error-while-loading kleinheit.datomic.impl
#error {
:cause "Call to clojure.core/refer-clojure did not conform to spec:\nIn: [2 1] val: :as fails at: [:args :exclude :op :quoted-spec :spec] predicate: #{:exclude}\nIn: [2 1] va......
@schmee It looks like you’re printing out the entire error record. Is it possible to just get the :cause
and print that?
Ah, I see. Can you perhaps write a wrapper function that calls the function in a try/catch?
@schmee Or, after you see an error like that, could you just do something like (println (:cause (ex-data *e)))
to print out the cause of the last error?
@schmee I haven’t tried this, but it looks like lein let’s you configure the error handler https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L357-L370. Note that by only printing the cause, you’ll presumably be losing other contextual information about the error, which may or may not be useful.
In any case, this isn’t really related to spec, so you may have more luck tracking down an answer in #leiningen . Good luck!
not currently
here’s how I’m doing it now, just curious if there is a better way:
(spec/def ::pred* (spec/cat :k any? :pred any?))
(spec/def ::pred (spec/with-gen (spec/and vector? ::pred*) #(gen/fmap vec (spec/gen ::pred*))))
@schmee My understanding is that vector sequences is a known problem that isn’t yet solved: https://clojurians.slack.com/archives/C1B1BB2Q3/p14988354
I feel like in some platonic sense the regex specs fit seqs much more than vectors but that doesn't mean it wouldn't be terribly useful to have regexes for vectors
probably mostly/entirely for macros?
We have cases where we like the succinctness of using vectors e.g. something like hiccup: [:p {} "hi"]
. When we manipulate it, it’s handy to have named parts by using a regex spec, but then we can unform it back to the vector form
there’s a JIRA for “specs-for-spec”: https://dev.clojure.org/jira/browse/CLJ-2112