{"id":13509151,"url":"https://github.com/josephwilk/amrita","last_synced_at":"2025-06-18T22:33:08.325Z","repository":{"id":8713462,"uuid":"10382366","full_name":"josephwilk/amrita","owner":"josephwilk","description":"A polite, well mannered and thoroughly upstanding testing framework for Elixir","archived":false,"fork":false,"pushed_at":"2017-07-07T14:41:26.000Z","size":1427,"stargazers_count":200,"open_issues_count":30,"forks_count":28,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-08T21:11:28.352Z","etag":null,"topics":["testing"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josephwilk.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":"2013-05-30T12:36:17.000Z","updated_at":"2024-12-11T22:02:43.000Z","dependencies_parsed_at":"2022-08-24T06:00:15.245Z","dependency_job_id":null,"html_url":"https://github.com/josephwilk/amrita","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/josephwilk/amrita","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwilk%2Famrita","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwilk%2Famrita/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwilk%2Famrita/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwilk%2Famrita/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josephwilk","download_url":"https://codeload.github.com/josephwilk/amrita/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwilk%2Famrita/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260643998,"owners_count":23041191,"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":["testing"],"created_at":"2024-08-01T02:01:03.635Z","updated_at":"2025-06-18T22:33:03.303Z","avatar_url":"https://github.com/josephwilk.png","language":"Elixir","funding_links":[],"categories":["Testing","Elixir"],"sub_categories":[],"readme":"# Amrita\n\n[![Build Status](https://travis-ci.org/josephwilk/amrita.svg?branch=master)](https://travis-ci.org/josephwilk/amrita)\n\nA polite, well mannered and thoroughly upstanding testing framework for [Elixir](http://elixir-lang.org/).\n\n![Elixir of life](http://s2.postimg.org/kmlrx9dp5/6337_33695901.jpg)\n\n## Install\n\nAdd to your mix.exs\n\n```elixir\n  defp deps do\n    [\n      {:amrita, \"~\u003e0.4\", github: \"josephwilk/amrita\"}\n    ]\n  end\n```\n\nAfter adding Amrita as a dependency, to install please run:\n\n```console\nmix deps.get\n```\n\n## Getting started\n\nEnsure you start Amrita in: test/test_helper.exs\n```elixir\nAmrita.start\n\n#Or if you want a more documentation focused formatter:\n\nAmrita.start(formatter: Amrita.Formatter.Documentation)\n```\n\n * Require test_helper.exs in every test (this will ensure Amrita is started):\n * Mix in `Amrita.Sweet` which will bring in everything you need to use Amrita:\n\n```elixir\nCode.require_file \"../test_helper.exs\", __ENV__.file\n\ndefmodule ExampleFacts do\n  use Amrita.Sweet\n\n  fact \"addition\" do\n    1 + 1 |\u003e 2\n  end\nend\n```\n\nRun your tests through mix:\n\n```shell\n$ mix amrita # Run all your tests\n\n$ mix amrita test/integration/t_mocks.ex # Run a specific file\n\n$ mix amrita test/integration/t_mocks.ex:10 # Run a specific test at a line number\n\n$ mix amrita --trace # Show execution time for slow tests\n```\n\nNow time to write some tests!\n\n## Prerequisites / Mocks\n\nAmrita supports BDD style mocks.\n\nExamples:\n\n```elixir\ndefmodule Polite do\n  def swear? do\n    false\n  end\n\n  def swear?(word) do\n    false\n  end\nend\n```\n\n#### A Simple mock\n```elixir\nfact \"mock with a wildcard\" do\n  provided [Polite.swear? |\u003e true] do\n    Polite.swear? |\u003e truthy\n  end\nend\n```\n\n#### Wildcard matchers for argument\n\n```elixir\nfact \"mock with a wildcard\"\n  provided [Polite.swear?(_) |\u003e true] do\n    Polite.swear?(:yes) |\u003e truthy\n    Polite.swear?(:whatever) |\u003e truthy\n  end\nend\n```\n\n#### Powerful custom predicates for argument matching\n```elixir\nfact \"mock with a matcher function\" do\n  provided [Polite.swear?(fn arg -\u003e arg =~ ~r\"moo\") |\u003e false] do\n    Polite.swear?(\"its ok to moo really\") |\u003e falsey\n  end\nend\n```\n\n#### Return values based on specific argument values\n```elixir\nfact \"mock with return based on argument\" do\n  provided [Polite.swear?(:pants) |\u003e false,\n            Polite.swear?(:bugger) |\u003e true] do\n\n    Funk.swear?(:pants) |\u003e falsey\n    Funk.swear?(:bugger) |\u003e truthy\n  end\nend\n```\n\n#### Polite Errors explaining when things went wrong\n\n![Polite mock error message](http://s9.postimg.org/wjwdo9dun/Screen_Shot_2013_07_19_at_20_11_17.png)\n\n\n## Checkers\n\nAmrita is also all about checker based testing!\n\n```elixir\nCode.require_file \"../test_helper.exs\", __ENV__.file\n\ndefmodule ExampleFacts do\n  use Amrita.Sweet\n\n  facts \"about Amrita checkers\" do\n    \n    fact \"`equals` checks equality\" do\n      1 - 10 |\u003e equals -9      \n      \n      # For convience the default checker is equals\n      # So we can write the above as\n      1 - 10 |\u003e -9\n            \n      # Pattern matching with tuples\n      { 1, 2, { 3, 4 } } |\u003e equals {1, _, { _, 4 } }\n\n      # Which is the same as \n      { 1, 2, { 3, 4 } } |\u003e {1, _, { _, 4 } }\n    end\n\n    fact \"contains checks if an element is in a collection\" do\n      [1, 2, 4, 5] |\u003e contains 4\n\n      {6, 7, 8, 9} |\u003e contains 9\n\n      [a: 1, :b 2] |\u003e contains {:a, 1}\n    end\n\n    fact \"! negates a checker\" do\n      [1, 2, 3, 4] |\u003e !contains 9999\n\n     # or you can add a space, like this. Whatever tickles your fancy.\n\n      [1, 2, 3, 4] |\u003e ! contains 9999\n\n      10 |\u003e ! equal 11\n    end\n\n    fact \"contains works with strings\" do\n      \"mad hatters tea party\" |\u003e contains \"hatters\"\n\n      \"mad hatter tea party\" |\u003e contains ~r\"h(\\w+)er\"\n    end\n\n    fact \"has_prefix checks if the start of a collection matches\" do\n      [1, 2, 3, 4] |\u003e has_prefix [1, 2]\n\n      {1, 2, 3, 4} |\u003e has_prefix {1, 2}\n\n      \"I cannot explain myself for I am not myself\" |\u003e has_prefix \"I\"\n    end\n\n    fact \"has_prefix with a Set ignores the order\" do\n      {1, 2, 3, 4} |\u003e has_prefix Set.new([{2, 1}])\n    end\n\n    fact \"has_suffix checks if the end of a collection matches\" do\n      [1, 2, 3, 4 ,5] |\u003e has_suffix [4, 5]\n\n      {1, 2, 3, 4} |\u003e has_suffix {3, 4}\n\n      \"I cannot explain myself for I am not myself\" |\u003e has_suffix \"myself\"\n    end\n\n    fact \"has_suffix with a Set ignores the order\" do\n      {1, 2, 3, 4} |\u003e has_suffix Set.new([{4, 3}])\n    end\n\n    fact \"for_all checks if a predicate holds for all elements\" do\n      [2, 4, 6, 8] |\u003e for_all even(\u00261)\n\n      # or alternatively you could write\n\n      [2, 4, 6, 8] |\u003e Enum.all? even(\u00261)\n    end\n\n    fact \"odd checks if a number is, well odd\" do\n      1 |\u003e odd\n    end\n\n    fact \"even checks is a number if even\" do\n      2 |\u003e even\n    end\n\n    fact \"roughly checks if a float within some +-delta matches\" do\n      0.1001 |\u003e roughly 0.1\n    end\n\n    fact \"falsey checks if expression evalulates to false\" do\n      nil |\u003e falsey\n    end\n\n    fact \"truthy checks if expression evaulates to true\" do\n      \"\" |\u003e truthy\n    end\n\n    defexception Boom, message: \"Golly gosh\"\n\n    fact \"raises checks if an exception was raised\" do\n      fn -\u003e raise Boom end |\u003e raises ExampleFacts.Boom\n    end\n  end\n\n  future_fact \"I'm not run yet, just printed as a reminder. Like a TODO\" do\n    # Never run\n    false |\u003e truthy\n  end\n\n  fact \"a fact without a body is much like a TODO\"\n\n  # Backwards compatible with ExUnit\n  test \"arithmetic\" do\n    assert 1 + 1 == 2\n  end\n\nend\n```\n\n## Assertion Syntax with |\u003e\n\nThe syntax for assertions is as follows:\n\n```elixir\n# Equality check\nACTUAL |\u003e [EXPECTED]\n# Not equal check\nACTUAL |\u003e ! [EXPECTED]\n\n# Using a checker function\nACTUAL |\u003e CHECKER [EXPECTED]\n# or negative form\nACTUAL |\u003e !CHECKER [EXPECTED]\n```\n\n\n##Custom checkers\n\nIts simple to create your own checkers:\n\n```elixir\n  defchecker a_thousand(actual) do\n    rem(actual, 1000) |\u003e equals 0\n  end\n\n  fact \"about 1000s\" do\n    1000 |\u003e a_thousand   # true\n    1200 |\u003e ! a_thousand # true\n  end\n```\n\n## Polite error messages:\n\nAmrita tries its best to be polite with its errors:\n\n![Polite error message](http://s24.postimg.org/vlj6epnmt/Screen_Shot_2013_06_01_at_22_12_16.png)\n\n## Amrita with Dynamo\n\nCheckout an example using Amrita with Dynamo: https://github.com/elixir-amrita/amrita_with_dynamo\n\n### Plugins\n\nSee the wiki for various IDE plugins for Amrita: https://github.com/josephwilk/amrita/wiki/Plugins\n\n## Amrita Development\n\nHacking on Amrita.\n\n###Running tests\n\nAmrita runs tests against Elixir's latest stable release and against Elixir master.\nMake is your friend for running these tests:\n\n```\n# Run lastest stable and elixir master\nmake ci\n\n# Run tests against your current Elixir install\nmake\n```\n\n### Docs\n\nhttp://josephwilk.github.io/amrita/docs\n\n## Bloody good show\n\nThanks for reading me, I appreciate it.\n\nHave a good day.\n\nMaybe drink some tea.\n\nIts good for the constitution.\n\n![Tea](http://s15.postimg.org/9dqs4g0wr/tea.png)\n\n##License\n(The MIT License)\n\nCopyright (c) 2014-2016 Joseph Wilk\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephwilk%2Famrita","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosephwilk%2Famrita","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephwilk%2Famrita/lists"}