{"id":13509239,"url":"https://github.com/xavier/plug_test_helpers","last_synced_at":"2025-10-21T15:21:40.224Z","repository":{"id":23866011,"uuid":"27244467","full_name":"xavier/plug_test_helpers","owner":"xavier","description":"A simple testing DSL for Plugs","archived":false,"fork":false,"pushed_at":"2014-11-30T10:39:57.000Z","size":121,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-01T09:34:26.186Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xavier.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":"2014-11-27T23:14:41.000Z","updated_at":"2023-09-14T14:40:46.000Z","dependencies_parsed_at":"2022-08-22T06:10:33.435Z","dependency_job_id":null,"html_url":"https://github.com/xavier/plug_test_helpers","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/xavier%2Fplug_test_helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavier%2Fplug_test_helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavier%2Fplug_test_helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavier%2Fplug_test_helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xavier","download_url":"https://codeload.github.com/xavier/plug_test_helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246323942,"owners_count":20759054,"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-08-01T02:01:05.007Z","updated_at":"2025-10-21T15:21:40.131Z","avatar_url":"https://github.com/xavier.png","language":"Elixir","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"# Plug Test Helpers\n\nSimple helpers to test your [Plugs](https://github.com/elixir-lang/plug) with ExUnit. Still an experiment in progress at this point.\n\nThe library provides a set of macros which can perform assertions on `Plug.Conn` structs to verify the response status, headers and body.\n\n## Installation\n\nAdd the dependency in your `mix.exs` file:\n\n```elixir\ndef deps do\n  [ { :plug_test_helpers, \"~\u003e 0.1\" } ]\nend\n```\n\nAfter you are done, run `mix deps.get` in your shell to get install it.\n\n## Usage\n\nAdd `use PlugTestHelpers` to your test case to bring in new Plug-specific assert macros :\n\n```elixir\n\ndefmodule do\n  use ExUnit.Case, async: true\n\n  use Plug.Test\n  use PlugTestHelpers\n\n  @opts MyPlug.init([])\n\n  test \"status\" do\n    conn = conn(:get, \"/\")\n    conn = MyPlug.call(conn, @opts)\n    assert_status 200\n  end\n\n  test \"404\" do\n    conn = conn(:get, \"/not-found\")\n    conn = MyPlug.call(conn, @opts)\n    # Works with symbols toos\n    assert_status :not_found\n  end\n\n  test \"redirect\" do\n    conn = conn(:get, \"/redirect\")\n    conn = MyPlug.call(conn, @opts)\n    # Will check both HTTP status code and header\n    assert_redirect \"http://example.com\"\n  end\n\n  test \"headers\" do\n    conn = conn(:get, \"/image.jpg\")\n    conn = MyPlug.call(conn, @opts)\n    # Will pass if the header is present\n    assert_header \"content_type\"\n    # Will pass if the header value is set to the given string\n    assert_header \"content_type\", \"image/jpg\"\n    # Will pass if the header value matches the given regex\n    assert_header_match \"content_type\", ~r/\\Aimage\\/jpe?g\\Z/\n  end\n\n  test \"body\" do\n    conn = conn(:get, \"/\")\n    conn = MyPlug.call(conn, @opts)\n    # Will pass if the response body is the given string\n    assert_body \"complete response text\"\n    # Will pass if the response body matches the given regex\n    assert_body_match ~r/complete/\n  end\n\nend\n\n```\n\n## Current Design Decisions\n\nThings may always change but these are the current design decisions taken to build this library.\n\n### Convention over Configuration\n\nEach of the `assert` macros expect a variable named `conn` to be bound to a `Plug.Conn`.\n\nThis is definitely a questionable design decision and I'd be very happy ot get some feedback about this.\n\nI think it's nice to have tests that are simple and concise. Is it worth providing macros accepting an extra `conn` parameter?\n\n### Advanced Response Body Assertions\n\nAssertions to match against structured response content (such as HTML or JSON) are currently out of the scope of this library.\n\n## License\n\nCopyright 2014 Xavier Defrang\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n```\nhttp://www.apache.org/licenses/LICENSE-2.0\n```\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxavier%2Fplug_test_helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxavier%2Fplug_test_helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxavier%2Fplug_test_helpers/lists"}