{"id":16372445,"url":"https://github.com/mgwidmann/stub_alias","last_synced_at":"2025-04-12T10:09:41.303Z","repository":{"id":57554346,"uuid":"58694908","full_name":"mgwidmann/stub_alias","owner":"mgwidmann","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-11T11:37:24.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T10:09:29.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mgwidmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-13T03:05:41.000Z","updated_at":"2025-02-11T11:37:29.000Z","dependencies_parsed_at":"2022-09-26T18:51:20.045Z","dependency_job_id":null,"html_url":"https://github.com/mgwidmann/stub_alias","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fstub_alias","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fstub_alias/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fstub_alias/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fstub_alias/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgwidmann","download_url":"https://codeload.github.com/mgwidmann/stub_alias/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248550634,"owners_count":21122933,"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":[],"created_at":"2024-10-11T03:11:25.263Z","updated_at":"2025-04-12T10:09:41.274Z","avatar_url":"https://github.com/mgwidmann.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stub Alias [![Hex.pm](https://img.shields.io/hexpm/v/stub_alias.svg)]()\n\nA simple macro to allow switching `alias` statements out with different values based upon environment.\n\n## Installation\n\n[Available in Hex](https://hex.pm/packages/stub_alias), the package can be installed as:\n\nAdd stub_alias to your list of dependencies in `mix.exs`:\n\n    def deps do\n      [{:stub_alias, \"~\u003e 0.1.0\"}]\n    end\n\n`StubAlias` is a compile time dependency and can be left out of the `applications` list.\n\n## Usage\n\nIn your code you may have some alias statements like the following:\n\n**EXAMPLE**\n\n```elixir\ndefmodule MyModule do\n  alias MyModule.Foo\n\n  def stuff() do\n    Foo.do_something_with_side_effects\n  end\nend\n```\n\nObviously, during testing, it makes it more difficult to test the function `stuff/0` since it calls another function which has undesierable side effects (or requires some system state like a running GenServer).\n\nIf you add to your `config/test.exs` configuration like the following:\n\n```elixir\nconfig :stub_alias,\n  \"MyModule.Foo\": MyModule.Stubs.Foo\n```\n\nSetup your mix.exs to compile in the `test/support` folder [like in Phoenix](https://github.com/phoenixframework/phoenix/blob/master/installer/templates/new/mix.exs#L12). Then replace `alias MyModule.Foo` with `stub_alias MyModule.Foo` (after `import StubAlias` of course):\n\n**SOLUTION**\n\n`lib/my_module.ex`\n```elixir\ndefmodule MyModule do\n  import StubAlias\n  stub_alias MyModule.Foo\n\n  def stuff() do\n    Foo.do_something_with_side_effects\n  end\nend\n```\n\n`test/support/foo.ex`\n```elixir\ndefmodule MyModule.Stubs.Foo do\n  def do_something_with_side_effects() do\n    # Return hard coded data or get data from an agent or whatever you please\n    results = %{}\n    results\n  end\nend\n```\n\n\nIn the `:test` Mix.env, your aliases will be replaced as desired. This then allows you to have a compiled `test/support` folder which supplies those stubs, making easy explicit replacements of code at test time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Fstub_alias","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgwidmann%2Fstub_alias","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Fstub_alias/lists"}