Fork me on GitHub
#clojure-spec
<
2017-01-25
>
bbloom03:01:10

@alexmiller i think you could get 90% of the way there with a smaller change than a custom stylesheet - Safari etc’s reader mode is broken on the current site b/c div#preamble doesn’t match div.sect1

bbloom03:01:18

i think that if you just make all the seconds have the same class, then reader modes will treat it all as body text and that’s a de facto print mode

Alex Miller (Clojure team)03:01:53

most of that did not actually mean anything to me :)

bbloom03:01:20

each page in the reference has multiple divs, but only the first div shows up if you use an article reading filter

Alex Miller (Clojure team)03:01:21

I’m like a monkey banging rocks together in web programming

bbloom03:01:57

you on a mac? go to any reference page in safari and you’ll see a little paragraph icon in the top left corner of the url bar

bbloom03:01:10

there’s various plugins for all the other browsers that do that too

bbloom03:01:53

but since the “preamble” in the generated pages have different structure and style classes applied, only that first section gets treated as body text

Alex Miller (Clojure team)03:01:45

so just some tweaks might fix that

bbloom03:01:19

yup, and then people can print that view just fine

Alex Miller (Clojure team)03:01:34

ok, if I get a chance I’ll see if I can muggle my way through it

bbloom03:01:37

an aria hint might do the trick super quick too

bbloom03:01:12

🙂 ARIA = accessible rich internet applications

bbloom03:01:16

it’s about accessibility

bbloom03:01:19

screen readers etc

bbloom03:01:46

the simplest thing to try:

bbloom03:01:50

wrap the entire content of the page in a <article> tag

bbloom03:01:44

specifically, change the div with class clj-content-container from div to article - and see if that does it

bbloom03:01:50

i bet that it does, no impact to styles at all

bbloom03:01:32

no problem. hopefully that helps 🙂

bbloom03:01:58

i abuse reader mode and use huge fonts for most stuff i read 🙂 i have good eye sight and hope to keep it that way!

Alex Miller (Clojure team)03:01:40

I match my font size to my age

bbloom03:01:00

heh, i like it

luxbock04:01:47

@alexmiller could you take a look at this and confirm if I'm using instrument correctly or if there might actually be an underlying issue with :gen https://gist.github.com/luxbock/ecb263750f61cc6fab7a736e5bd96008

Alex Miller (Clojure team)04:01:37

I will take a look in the morning

nick05:01:14

Maybe this is silly but say I have a spec like this (s/def ::dog (s/keys ::req [::name ::type ::sound])) but I also want to include a key that's always something specific like :feet 4 - so if I generate that I'll get like {:name "red" :type "golden retriever" :sound "woofwoof" :feet 4}

nick06:01:47

I want to do something like this:

(defmulti dog-type :dog/type)
(defmethod dog-type :golden-retriever [_]
  (s/keys :req [::name ::sound]))
But also have in the keys a type key that is dog-type and the actual key.

tengstrand06:01:17

Is it possible to use spec to validate maps that has keys that are not namespaced, like :name instead of :user/name?

seancorfield07:01:49

@teng Yes, with :req-un and :opt-un. Although they require namespaced keys for the specs, the actual map keys are unqualified.

seancorfield07:01:05

(see the guide for more details)

seancorfield07:01:46

@nick Do you mean you'd want (s/def ::feet #{4}) as the spec for the :feet key?

odinodin12:01:12

(clojure.spec/explain string? 123)
val: 123 fails predicate: :clojure.spec/unknown
How can I get the predicate to show string?

dominicm12:01:27

@odinodin I think you need to do (s/def ::string? string) and then you can (s/explain ::string? 123)

odinodin12:01:50

@dominicm thanks, makes sense 🙂

Alex Miller (Clojure team)13:01:20

This unknown is a bug that has a pending patch btw

Alex Miller (Clojure team)13:01:36

So that will work eventually

odinodin13:01:20

@alexmiller that is awesome 🙂

Alex Miller (Clojure team)15:01:36

@luxbock I agree that I’d expect something like this to work. I did just notice this line in the instrument docs though: ":gen overrides are used only for :stub generation.” which honestly surprises me. it seems like they should be used also for instrumented :args gen too.

Alex Miller (Clojure team)15:01:13

although maybe you should really be passing those :gen overrides in your call to check

Alex Miller (Clojure team)15:01:41

yeah, you should move your gen overrides map from instrument into the check options map. also, in the :gen map, the values should be no-arg functions that return the generator, not the actual generator, so just prefix all of them with # to turn them into anonymous no-arg functions

Alex Miller (Clojure team)15:01:27

once I did that, it was running, but I started getting OOMEs

Alex Miller (Clojure team)15:01:12

to address that, I narrowed the collection generators which default to max size 20. I added :gen-max 3 to both the fdef :args spec and the ::operations override gen.

luxbock15:01:13

@alexmiller ah yeah I think I tried :gen with check but I didn't realize that I need to wrap them in thunks

luxbock15:01:42

thanks, I will play around with it a bit more later today

Alex Miller (Clojure team)15:01:28

these days I generally preemptively add :gen-max 3 to all collection specs reachable by fdef :args or used in recursion

Alex Miller (Clojure team)15:01:51

I think it would be a good idea to change the default there from 20 to 3

luxbock15:01:16

yeah that's good to know as well

Alex Miller (Clojure team)15:01:19

if you’d like to vote :)

luxbock15:01:59

it feels that all the spec related testing functionality one needs to write these types of tests is quite spread out, both in terms of namespaces and where the different options for customizing the generators go

luxbock15:01:53

nothing that a good utility library won't fix, but I have a hard time keeping in my head where everything is supposed to come from and how it ties together

Alex Miller (Clojure team)15:01:35

well the stuff in spec vs spec.test is intentionally split to emphasize the parts that are designed specifically for testing. and spec.gen is the same - split out the part that dynamically loads and depends on test.check generators.

Alex Miller (Clojure team)15:01:48

those are at this point pretty well factored in my mind

Alex Miller (Clojure team)15:01:22

the gen overrides stuff is a bit messier and not consistent enough between s/exercise, stest/instrument, stest/check etc and we may still make some changes in those

luxbock16:01:32

I'm writing code which I can't fully test in use until it hits the production server so I'm trying to cover as many edge cases as possible with spec and generative tests to avoid the long feedback loop of deploy + test, and it's definitely giving me a lot more confidence in that I got rid of most of the silly bugs before trying it in actual use

Alex Miller (Clojure team)16:01:34

cool, that’s good to hear

ag20:01:05

quick noob question how do I limit the size of a number in spec like: (s/and int? pos?)

qqq21:01:08

@ag: you can pass in arbitrary function

qqq21:01:24

if you also need to generate, you need to write you rown generator

Alex Miller (Clojure team)21:01:32

@ag (s/and int? pos-int? #(< % 100)

Alex Miller (Clojure team)21:01:45

but once you start going there, consider integer ranges

Alex Miller (Clojure team)21:01:17

the range specs come with a better generator by default

ag21:01:50

ah, right… thanks @alexmiller

ag23:01:23

uh… so how do I make a spec for a key like this

:options {:on-click `~(fn [r] ,,,,)}
it contains an fn but in quoted form?

ag23:01:02

I guess I need s/fdef, how do I make a spec for something like {:on-click (fn [e],,,} - function that takes one argument of anything and returns whatever?