{"id":15010673,"url":"https://github.com/zhming0/mock-clj","last_synced_at":"2025-04-09T18:34:29.548Z","repository":{"id":62433688,"uuid":"78496205","full_name":"zhming0/mock-clj","owner":"zhming0","description":"A minimalist \u0026 non-invasive API for mocking in Clojure","archived":false,"fork":false,"pushed_at":"2022-12-20T04:29:00.000Z","size":16,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T23:47:40.609Z","etag":null,"topics":["clojure","mocking","testing"],"latest_commit_sha":null,"homepage":null,"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/zhming0.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-01-10T04:03:26.000Z","updated_at":"2022-12-20T04:29:11.000Z","dependencies_parsed_at":"2023-01-29T23:45:47.685Z","dependency_job_id":null,"html_url":"https://github.com/zhming0/mock-clj","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhming0%2Fmock-clj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhming0%2Fmock-clj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhming0%2Fmock-clj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhming0%2Fmock-clj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhming0","download_url":"https://codeload.github.com/zhming0/mock-clj/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248088263,"owners_count":21045671,"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","mocking","testing"],"created_at":"2024-09-24T19:35:18.207Z","updated_at":"2025-04-09T18:34:29.533Z","avatar_url":"https://github.com/zhming0.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mock-clj\n\n[![Build Status](https://travis-ci.org/zhming0/mock-clj.svg?branch=master)](https://travis-ci.org/zhming0/mock-clj)\n[![Clojars Project](https://img.shields.io/clojars/v/mock-clj.svg)](https://clojars.org/mock-clj)\n\nMinimalist \u0026 non-invasive API for mocking in Clojure. \nOverall, it is a syntax sugar around `with-redefs`. \nIt leverages Clojure's unique metadata mechanism to offer common test/assertion utilities for mocking/stubbing.\n\n## Usage\n\n```clojure\n(with-mock specs \u0026 body)\n```\n\n`specs =\u003e var-symbol value-expr/functions`\n\nTemporarily redefines `var` while executing `body`. \nIf the right-hand side of a spec is a value, then it will create a function constantly returning the value (stub).\nIf the right-hand side of a spec is a function, then the var-symbol will temporarily be replaced by the function.\n\n### Features \u0026 Example \n\n#### Track mock's invocation history\n\n```clojure\n\n(require ['mock-clj.core :as 'mc])\n\n(defn foo [a] (str \"foo\" a))\n\n(defn bar [a] (str (foo a) \"bar\"))\n\n(deftest test-bar\n  (mc/with-mock [foo \"oof\"] ; equals to [foo (constantly \"oof\")] \n    (is (= (bar \"test\") \"oofbar\"))\n    ; Calls history\n    (is (= (mc/calls foo) [[\"test\"]]))\n    ; Last-call\n    (is (= (mc/last-call foo) [\"test\"]))\n    ; call-count\n    (is (= 1 (mc/call-count foo)))\n    ; Called? \n    (is (mc/called? foo))))\n\n```\n\n#### Mock private functions with ease\n\n```clojure\n(ns ns-a)\n(defn- g [] true)\n(defn f [a] (g))\n\n(ns ns-b)\n(deftest mock-private-test\n  (with-mock [#'ns-a/g \"baz\"]\n    (is (= (#'ns-a/f \"foo\") \"baz\"))))\n\n```\n\n(Note: generally, it's not a good idea to mock private functions)\n\n## License\n\nCopyright © 2017 Ming\n\nDistributed under the Eclipse Public License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhming0%2Fmock-clj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhming0%2Fmock-clj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhming0%2Fmock-clj/lists"}