This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-26
Channels
- # architecture (2)
- # beginners (83)
- # boot (472)
- # cider (10)
- # cljsrn (4)
- # clojure (80)
- # clojure-russia (7)
- # clojure-spec (34)
- # clojure-taiwan (1)
- # clojure-uk (7)
- # clojurescript (19)
- # core-async (5)
- # emacs (7)
- # figwheel (1)
- # hoplon (52)
- # jobs (1)
- # luminus (14)
- # om (1)
- # om-next (3)
- # perun (69)
- # proton (2)
- # protorepl (4)
- # re-frame (28)
- # reagent (6)
- # remote-jobs (1)
I have this error message :
(clojure.spec.gen/generate (clojure.spec/gen :paintings2.routes.home/page))
RuntimeException Var clojure.test.check.generators/large-integer is not on the classpath clojure.spec.gen/dynaload (gen.clj:21)
on this code :
(ns paintings2.routes.home
(:require [paintings2.layout :as layout]
[compojure.core :refer [defroutes GET]]
[ring.util.http-response :as response]
[ :as io]
[compojure.route :refer [resources]]
[environ.core :refer [env]]
[paintings2.api-get :as api]
[clj-http.client :as client]
[clojure.spec :as s]))
(defn ->long [s] (try (Long/parseLong s) (catch Exception _ ::s/invalid)))
(s/def ::page (s/and (s/conformer ->long) (s/int-in 1 471)))
(s/def ::optional-page (s/nilable ::page))
(defn page-check [page] (let [page page page-num (or (s/conform ::optional-page page) 1)] page-num))
(s/fdef page-check
:args (string? (::page :page))
:ret (number? (::page :page))
:fn (s/valid? true? (::page :page) )
)
and I have this in my projects.clj :
:profiles {:dev {:dependencies [[org.clojure/test.check "0.9.0"]
]}}
see my last response, @joshjones
(defproject your-project "1.0"
:description "spec playground"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:dependencies [[org.clojure/clojure "1.9.0-alpha14"]
[org.clojure/test.check "0.9.0"]])
oke, now I see another error message :
ExceptionInfo Unable to construct gen at: [] for: (conformer ->long) clojure.core/ex-info (core.clj:4725)
now you're getting somewhere -- i get why you want to use a conformer, but i've not used a conformer to generate data before, nor have i seen any info on doing so -- only seen info on conforming/validating using a conformer
the way you've written the spec for ::page
, I do not think there's enough info there for it to do any data generation
oke, what I try to do it this : The user can use this url : http://localhost:3000/
or the user can use this url : http://localhost/?page=n
@joshjones so far, clear ?
so n could be "a" then the outcome is invalid or "124" then the outcome is 124 or "500" then the outcome is also invalid
(defn gen-page-num
[]
(gen/fmap #(str %) (s/gen (s/int-in 1 471))))
(s/def ::page
(s/spec (s/and (s/conformer ->long) (s/int-in 1 471))
:gen gen-page-num))
You might want to keep this level of back and forth in the #beginners channel
@joshjones my code for the url parsing with the pagenumber could be find here : https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/routes/home.clj
@seancorfield The last question is about spec because josh thinks that my fdef for testing and generating test-data is not good
@roelof Use the above generator and revised def for ::page
and you'll be able to generate data using ::page
@joshjones Am I right that I cannot check what happens if a user enters false data like this : ' /?pag="a"
@roelof Although this is about clojure.spec
, there are still a lot of beginner-level issues at play here so I’d suggest keeping to the #beginners channel where folks have opted into helping folks with this level of discussion, rather than swamping the other channels with long back and forth about syntax and basic errors.