{"id":15645990,"url":"https://github.com/borkdude/respeced","last_synced_at":"2025-04-14T03:14:44.884Z","repository":{"id":57713971,"uuid":"160724359","full_name":"borkdude/respeced","owner":"borkdude","description":"Testing library for clojure.spec fdefs","archived":false,"fork":false,"pushed_at":"2022-10-29T12:19:37.000Z","size":42,"stargazers_count":51,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T03:14:29.302Z","etag":null,"topics":["clojure","clojure-spec","testing"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borkdude.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-06T19:52:37.000Z","updated_at":"2025-03-24T07:29:17.000Z","dependencies_parsed_at":"2022-08-25T10:31:16.856Z","dependency_job_id":null,"html_url":"https://github.com/borkdude/respeced","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frespeced","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frespeced/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frespeced/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frespeced/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borkdude","download_url":"https://codeload.github.com/borkdude/respeced/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813803,"owners_count":21165634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","clojure-spec","testing"],"created_at":"2024-10-03T12:10:54.129Z","updated_at":"2025-04-14T03:14:44.844Z","avatar_url":"https://github.com/borkdude.png","language":"Clojure","funding_links":[],"categories":["Clojure"],"sub_categories":[],"readme":"# respeced\n[![CircleCI](https://circleci.com/gh/borkdude/respeced/tree/master.svg?style=svg)](https://circleci.com/gh/borkdude/respeced/tree/master)\n[![Clojars Project](https://img.shields.io/clojars/v/respeced.svg)](https://clojars.org/respeced)\n[![cljdoc badge](https://cljdoc.org/badge/respeced/respeced)](https://cljdoc.org/d/respeced/respeced/CURRENT)\n\nTesting library for clojure.spec fdefs.\n\n## Rationale\n\nThis library helps verify that [spec](https://clojure.org/about/spec) `fdefs` do\nwhat they are supposed to do:\n\n- throw errors on non-valid arguments and return values\n- not throw on valid arguments and return values\n\nA good illustration of the intended usage of this library can be seen in tests\nfor the\n[speculative](https://github.com/slipset/speculative/blob/master/test/speculative/core_test.cljc)\nlibrary, where this library originated from.\n\nRespeced fully supports Clojure, ClojureScript and self-hosted ClojureScript.\n\n## Installation\n\n### deps.edn\n\n```\nrespeced/respeced {:mvn/version \"0.1.2\"}\n```\n\n### leiningen\n\n```\n[respeced \"0.1.2\"]\n```\n\n## API\n\n### `with-instrumentation`\nInstrument a function in the scope of a body. Restores instrumentation state,\ni.e. unstruments after the call only when the function was not instrumented\nbefore the call.\n\nExample call:\n\n```clojure\n(with-instrumentation `foo (foo 1 2 3))\n```\n\n### `with-unstrumentation`\nUnstrument a function in the scope of a body. Restores instrumentation state,\ni.e. only re-instruments after the call when the function was instrumented\nbefore the call.\n\nExample call:\n\n```clojure\n(with-unstrumentation `foo (foo 1 2 3))\n```\n\n### `caught?`\nReturns `true` if body throws spec error for instrumented fn.\n\nExample call:\n\n```clojure\n(deftest my-fdef-works\n  (with-instrumentation `foo\n    (is (caught? `foo (foo :some-wrong-argument))))\n```\n\n### `check-call`\nApplies args to function resolved by symbol. Checks `:args`, `:ret` and `:fn`\nspecs. Returns return value of call if succeeded, else throws.\n\nExample call:\n\n```clojure\n(is (= [4 5 6] (check-call `foo [1 2 3])))\n```\n\n### `check`\nLike `clojure.spec.test.alpha/check` with third arg for passing\n`clojure.test.check` options.\n\nExample call:\n\n```clojure\n(check `foo {} {:num-tests 10})\n```\n\n### `successful?`\nReturns `true` if all `clojure.spec.test.alpha/check` tests have `pass?` `true`.\n\nExample call:\n\n```clojure\n(successful? (check `foo {} {:num-tests 10}))\n```\n\n## Example usage\n\n``` clojure\n$ clj -Sdeps '{:deps {respeced/respeced {:mvn/version \"0.1.2\"}}}'\nClojure 1.10\n\nuser=\u003e (require '[respeced.test :as rt])\nnil\n\nuser=\u003e (require '[clojure.spec.alpha :as s])\nnil\n\nuser=\u003e (s/fdef foo :args (s/cat :n number?) :ret number?)\nuser/foo\n\n;; this function has the wrong return value according to the spec:\n\nuser=\u003e (defn foo [n] \"ret\")\n#'user/foo\n\n;; rt/check-call helps with checking `:ret` and `:fn` specs:\n\nuser=\u003e (rt/check-call `foo [1])\nExecution error - invalid arguments to respeced.test$do_check_call/invokeStatic at (test.cljc:138).\n\"ret\" - failed: number? at: [:ret]\n\n;; change the spec:\n\nuser=\u003e (s/fdef foo :args (s/cat :n number?) :ret string?)\nuser/foo\n\n;; no error anymore:\n\nuser=\u003e (rt/check-call `foo [1])\n\"ret\"\n\n;; instrument a function within a scope:\n\nuser=\u003e (rt/with-instrumentation `foo (foo \"a\"))\nExecution error - invalid arguments to user/foo at (REPL:1).\n\"a\" - failed: number? at: [:n]\n\n;; not instrumented:\n\nuser=\u003e (foo \"a\")\n\"ret\"\n\n;; `rt/check` has a third arg for passing `clojure.test.check` options:\n\nuser=\u003e (rt/check `foo nil {:num-tests 1})\ngeneratively testing user/foo\n({:spec #object[clojure.spec.alpha$fspec_impl$reify__2524 0x72bd06ca \"clojure.spec.alpha$fspec_impl$reify__2524@72bd06ca\"], :clojure.spec.test.check/ret {:result true, :pass? true, :num-tests 1, :time-elapsed-ms 1, :seed 1541249961647}, :sym user/foo})\n\n;; validate if generative test was successful:\n\nuser=\u003e (rt/successful? *1)\ntrue\n\nuser=\u003e\n```\n\n## Tests\n\nRequires [babashka](https://github.com/babashka/babashka#installation).\n\nThe tests can be called with an optional `deps.edn` alias argument to\nspecify the Clojure(Script) version to load, e.g.\n\n`bb clj-tests :1.10`\n\n### All tests\n\n`bb test`\n\n### Clojure\n\n`bb clj-tests`\n     \n### ClojureScript\n\n`bb cljs-tests`\n    \n## License\n\nCopyright © 2018-2022 Michiel Borkent\n\nDistributed under the EPL License, same as Clojure. See LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborkdude%2Frespeced","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborkdude%2Frespeced","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborkdude%2Frespeced/lists"}