ring-clojure / ring-mock Goto Github PK
View Code? Open in Web Editor NEWThis project forked from weavejester/ring-mock
Library to create mock Ring requests for unit tests
License: MIT License
This project forked from weavejester/ring-mock
Library to create mock Ring requests for unit tests
License: MIT License
Hi,
API documentation is broken, there is wrong link in "view source" buttons.
For example:
https://github.com/ring-clojure/ring/blob/0.3.1/src/ring/mock/request.clj#L56 (Error 404)
I think https://github.com/ring-clojure/ring-mock/blob/0.3.1/src/ring/mock/request.clj#L56 (Working) should be better
Bye :)
Originally opened as weavejester#15
A built-in support for mocking multipart uploads would be nice.
In #9, @danielcompton gives a workaround using Peridot's peridot.multipart/build
:
(-> (ring.mock.request/request :post "/my-file-upload")
(merge (peridot.multipart/build {:data (io/file (io/resource "data.csv"))}))
(app))
Peridot's implementation uses org.apache.httpcomponents/httpmime
.
Maybe a similar function signature like (ring.mock.request/multipart request map)
could be used, where the map keys would be strings and values could be either strings or files.
There's no LICENSE.md file for the specified MIT license. More and more OSS tools are scanning for these and concluding ring-mock doesn't have a specified license.
Hi - In the 3rd example, I am not sure what the function json-body
is doing:
(is (= (your-handler (-> (mock/request :post "/api/endpoint")
(json-body {:foo "bar"})))
Mock request does not generate :protocol as per Ring SPEC
:protocol
(Required, String)
The protocol the request was made with, e.g. "HTTP/1.1".
and fails to conform to the following spec:
(s/def :ring/request
(s/keys :req-un [:ring.request/server-port
:ring.request/server-name
:ring.request/remote-addr
:ring.request/uri
:ring.request/scheme
:ring.request/protocol
:ring.request/headers
:ring.request/request-method]
:opt-un [:ring.request/query-string
:ring.request/body]))
from ring-spec
:content-type "application/x-www-form-urlencoded",
must in
:headers {"cookie" "ring-session=testuser" "content-type" "application/x-www-form-urlencoded; charset=UTF-8"}
Please. I'd love to my hands on #12.
Thanks, James!
Would it be possible to support mocking websocket requests, so that websocket servers could be tested without starting a server?
I have not been able to find any Clojure project that would test websockets without starting a server.
Found while trying to fix #3. Upgrading dependency to clojure 1.7.0 fixed the issue; not sure how you'd like to proceed.
error in process sentinel: Could not start nREPL server: Error loading cider.nrepl.middleware.apropos: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.classpath: java.lang.RuntimeException: Unable to resolve symbol: response-for in this context, compiling:(cider/nrepl/middleware/classpath.clj:15)
Error loading cider.nrepl.middleware.complete: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.debug: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.format: java.lang.RuntimeException: Unable to resolve symbol: defprotocol+ in this context, compiling:(deps/cljfmt/v0v1v10/deps/rewrite_clj/v0v4v12/rewrite_clj/node/protocols.clj:9)
Error loading cider.nrepl.middleware.info: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.inspect: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.macroexpand: java.lang.RuntimeException: Unable to resolve symbol: response-for in this context, compiling:(cider/nrepl/middleware/macroexpand.clj:73)
Error loading cider.nrepl.middleware.ns: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.pprint: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.refresh: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.resource: java.lang.RuntimeException: Unable to resolve symbol: defsource in this context, compiling:(deps/compliment/v0v2v4/compliment/sources/resources.clj:42)
Error loading cider.nrepl.middleware.stacktrace: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.test: java.lang.RuntimeException: Unable to resolve symbol: some-> in this context, compiling:(cider/nrepl/middleware/util/cljs.clj:57)
Error loading cider.nrepl.middleware.trace: java.lang.RuntimeException: Unable to resolve symbol: response-for in this context, compiling:(cider/nrepl/middleware/trace.clj:16)
Error loading cider.nrepl.middleware.undef: java.lang.RuntimeException: Unable to resolve symbol: response-for in this context, compiling:(cider/nrepl/middleware/undef.clj:19)
Error loading refactor-nrepl.middleware: java.lang.RuntimeException: Unable to resolve symbol: reduce-kv in this context, compiling:(deps/toolsanalyzerjvm/v0v6v6/deps/toolsanalyzer/v0v6v5/clojure/tools/analyzer/utils.clj:49)
Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: cider.nrepl.middleware.apropos/wrap-apropos in this context, compiling:(/private/var/folders/2w/kffqc_pj6m38rgrxlhk8z6nr0000gn/T/form-init7593186812270114693.clj:1)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6416)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.analyze(Compiler.java:6177)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3503)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6411)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.analyze(Compiler.java:6177)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3503)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6411)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.access$100(Compiler.java:37)
at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:5837)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6409)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.analyze(Compiler.java:6177)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5572)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5008)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3629)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6407)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.eval(Compiler.java:6462)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.load(Compiler.java:6902)
at clojure.lang.Compiler.loadFile(Compiler.java:6863)
at clojure.main$load_script.invoke(main.clj:282)
at clojure.main$init_opt.invoke(main.clj:287)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: cider.nrepl.middleware.apropos/wrap-apropos in this context
at clojure.lang.Util.runtimeException(Util.java:156)
at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:613)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6409)
... 33 more
Subprocess failed
Hi!
It seems that the newest version of ring-mock ("0.3.0") no longer accepts a body
in a DELETE request?
I have some API here that I would like to test which requires to pass along
content as the body of a DELETE request. Sadly that doesn't work right now in
the latest version.
The http spec doesn't disallow having a body in the request, although it warns
that some servers may ignore it. (Jetty, the one I'm using, doesn't ignore it).
As per http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19
Bodies on DELETE requests have no defined semantics. Note that sending a body
on a DELETE request might cause some existing implementations to reject the
request.
Also see this stackoverflow answer.
an entity-body is explicitly forbidden in TRACE requests only, all other
request types are unrestricted (section 9, and 9.8 specifically)
(emphasis mine)
Seems like this was introduced in 38471fa
As it stands, this seems like a decision that should be done by the server
(e.g Jetty) rather than by the client (this library).
Is there any hope in this being changed back to the original implementation?
If not, at least this should be noted somewhere in the documentation.
Hi,
I'm currently simulating file upload via the following CURL command:
curl -v -XPOST -F filedata=@my_file.png localhost:3000/upload_endpoint
I want to simulate file uploads in tests but setting the Content-Type header with boundaries and a proper body like HTTP multipart spec requires is kind of tiresome.
Is there a good way to simulate file uploads via ring-mock?
Thanks in advance.
Hi @weavejester,
Would you mind releasing a 0.3.3 version with changes related to codox, remote-addr and mock/cookie ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.