{"id":15503352,"url":"https://github.com/rickmoynihan/redef-methods","last_synced_at":"2025-10-31T07:31:11.100Z","repository":{"id":66459040,"uuid":"169075347","full_name":"RickMoynihan/redef-methods","owner":"RickMoynihan","description":"Stub clojure multi-method bodies","archived":false,"fork":false,"pushed_at":"2020-06-03T07:34:49.000Z","size":12,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-29T11:37:16.237Z","etag":null,"topics":["clojure","integrant","multi-methods","stub","stubbing","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-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RickMoynihan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-04T12:30:09.000Z","updated_at":"2024-11-28T12:29:30.000Z","dependencies_parsed_at":"2023-03-10T23:57:41.432Z","dependency_job_id":null,"html_url":"https://github.com/RickMoynihan/redef-methods","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickMoynihan%2Fredef-methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickMoynihan%2Fredef-methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickMoynihan%2Fredef-methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickMoynihan%2Fredef-methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RickMoynihan","download_url":"https://codeload.github.com/RickMoynihan/redef-methods/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239137373,"owners_count":19587991,"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","integrant","multi-methods","stub","stubbing","testing"],"created_at":"2024-10-02T09:12:54.337Z","updated_at":"2025-10-31T07:31:05.804Z","avatar_url":"https://github.com/RickMoynihan.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Clojars Project](https://img.shields.io/clojars/v/tube-alloys/redef-methods.svg)](https://clojars.org/tube-alloys/redef-methods)\n\n# redef-methods\n\nA tiny Clojure library consisting of a single macro\n`with-redef-methods` that allows you to stub defmethod multi-method\nbodies.  Like Clojure's `with-redefs` but for `defmethods`, not vars.\n\n## When might I use this?\n\nThe main use case is for tests, where you want to stub out a specific\ndefmethod for a particular dispatch value.\n\nIn particular it was written to aid testing\n[integrant](https://github.com/weavejester/integrant) allowing you to\nselectively stub out small parts of a larger integrant system.\n\nThe macro though is fully generic and can be used in any clojure\n(1.9.0+) code base.\n\nYou could for example also use it to introduce new thread local method\ndispatches.  Not that I would recomend such a thing!\n\n**WARNING**: You may run into some problems using this with `ig/load-namespaces`\nand tools.namespace.\n\n## Example\n\nThere exists a multi-method with one or more method bodies:\n\n```clojure\n(defmulti wibble (fn [key arg] key))   ;; dispatch on first argument\n\n(defmethod wibble :foo [_ arg]\n  :foo-body)\n\n(defmethod wibble :bar [_ arg]\n  :bar-body)\n\n\n(wibble :foo 1) ;; =\u003e :foo-body\n\n(wibble :bar 1) ;; =\u003e :bar-body\n```\n\n... and you want to stub them thread locally:\n\n```clojure\n(require '[tube-alloys.redef-methods :refer [with-redef-methods]])\n\n(with-redef-methods [wibble {:foo (fn [key arg]\n                                     :foo-override)}]\n\n ;; Within this thread local dynamic scope (wibble :foo xxx) will trigger our\n ;; override function and return `:foo-override` instead of the original `defmethod`\n ;; body.\n\n (wibble :foo 1) ;; =\u003e :foo-override\n )\n\n;; Outside of the binding scope we get our original implementation:\n\n(wibble :foo 1) ;; =\u003e :foo-body\n```\n\n## With special thanks to...\n\n[Weavejester](https://github.com/weavejester) for coming up with the\nidea [whilst discussing](https://clojurians-log.clojureverse.org/duct/2019-02-01/1549034715.119700)\napproaches to testing integrant systems.\n\n## License\n\nCopyright © 2019 Rick Moynihan\n\nThis program and the accompanying materials are made available under the\nterms of the Eclipse Public License 2.0 which is available at\nhttp://www.eclipse.org/legal/epl-2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickmoynihan%2Fredef-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frickmoynihan%2Fredef-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickmoynihan%2Fredef-methods/lists"}