Skip to content

Latest commit

 

History

History
74 lines (65 loc) · 1.8 KB

README.md

File metadata and controls

74 lines (65 loc) · 1.8 KB

clj-moco Clojars Project

CircleCI An easy setup stub framework in Clojure, wrapping Moco.

Usage

1. matches jsonpath

(respond (matches (http-server 12306) (eq (json-path "$.book.price") "1")) "foo")
or
(-> (http-server 12306)
    (matches (eq (json-path "$.book.price") "1"))
    (respond "foo"))

2. matches json

(respond (matches (http-server 12306) (json "{\"foo\":\"bar\"}")) "foo")
or
(-> (http-server 12306)
    (matches (json "{\"foo\":\"bar\"}"))
    (respond "foo"))

3. matches map

(respond (matches (http-server 12306) (map->json {:code 1 :message "message"})) "foo")
or
(-> (http-server 12306)
    (matches (map->json {:code 1 :message "message"}))
    (respond "foo"))

4. exists jsonpath

(respond (matches (http-server 12306) (exists (json-path "$.book.price"))) "foo")
or
(-> (http-server 12306)
    (matches (exists (json-path "$.book.price")))
    (respond "foo"))

5. respond something

(-> (http-server 12306)
    (respond "foo"))

6. respond a file

(-> (http-server 12306)
    (respond (->file "resources/foo.response")))

7. by uri

(-> (http-server 12306)
    (matches (by (uri "/foo")))
    (respond "bar"))

8. and/or predicate

(require '[predicates :as p])
(-> (http-server 12306)
    (matches (p/and (by "foo") (by (uri "/foo"))))
    (respond "bar"))
    
(-> (http-server 12306)
    (matches (p/or (by "foo") (by (uri "/foo"))))
    (respond "bar"))    

License

Copyright © 2016 lambeta

Distributed under the Eclipse Public License either version 1.0