{"action":"created","issue":{"url":"https://api.github.com/repos/phoenixframework/phoenix/issues/767","labels_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/767/labels{/name}","comments_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/767/comments","events_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/767/events","html_url":"https://github.com/phoenixframework/phoenix/issues/767","id":68314200,"number":767,"title":"Provide sent/2, sent_html/2, etc in connection test","user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phoenixframework/phoenix/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/phoenixframework/phoenix/labels/level:intermediate","name":"level:intermediate","color":"eb6420"},{"url":"https://api.github.com/repos/phoenixframework/phoenix/labels/testing","name":"testing","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/phoenixframework/phoenix/milestones/8","html_url":"https://github.com/phoenixframework/phoenix/milestones/v0.12","labels_url":"https://api.github.com/repos/phoenixframework/phoenix/milestones/8/labels","id":1059615,"number":8,"title":"v0.12","description":"","creator":{"login":"chrismccord","id":576796,"avatar_url":"https://avatars.githubusercontent.com/u/576796?v=3","gravatar_id":"","url":"https://api.github.com/users/chrismccord","html_url":"https://github.com/chrismccord","followers_url":"https://api.github.com/users/chrismccord/followers","following_url":"https://api.github.com/users/chrismccord/following{/other_user}","gists_url":"https://api.github.com/users/chrismccord/gists{/gist_id}","starred_url":"https://api.github.com/users/chrismccord/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrismccord/subscriptions","organizations_url":"https://api.github.com/users/chrismccord/orgs","repos_url":"https://api.github.com/users/chrismccord/repos","events_url":"https://api.github.com/users/chrismccord/events{/privacy}","received_events_url":"https://api.github.com/users/chrismccord/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":1,"state":"open","created_at":"2015-04-09T02:27:04Z","updated_at":"2015-04-14T09:21:04Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2015-04-14T09:20:29Z","updated_at":"2015-04-14T19:04:28Z","closed_at":null,"body":"Today, we want at least to assert three things in a controller test:\r\n\r\n1. What is the status code\r\n2. What is the content type\r\n3. What is the response body\r\n\r\nThe only way to do this if with 3 assertions today:\r\n\r\n```elixir\r\nassert conn.status == 200\r\nassert get_resp_header(conn, \"content-type\") =~ \"text/html\"\r\nassert conn.resp_body =~ \"some body\"\r\n```\r\n\r\nThis approach is, however, very verbose. I would like to introduce some helpers to make it easier for us to assert those things. For example, we could rewrite all above as:\r\n\r\n```elixir\r\nassert sent_html(conn, 200) =~ \"some body\"\r\n```\r\n\r\n`sent_html/2` checks if a response was sent, checks the status code, the content type and returns the response body. We can also provide `sent_json/2`, similar to above, but that also already decodes the response:\r\n\r\n```elixir\r\nbody = sent_json(conn, 200)\r\nassert body[\"errors\"] == ...\r\n```\r\n\r\nBoth those helpers will be built on top of `sent/2`, which works as above, except it doesn't check the content type.\r\n\r\nFinally, we should also have a helper for `redirected_to`, which has already been added to master:\r\n\r\n```elixir\r\nassert redirected_to(conn) == \"/path/it/was/redirected/to\"\r\nassert redirected_to(conn, 301) == \"/path/it/was/redirected/to\"\r\n```\r\n\r\nThose functions can also help us in providing better error messages until we improve the reporting mechanism in ExUnit. Thoughts? /cc @chrismccord @parkerl @batate"},"comment":{"url":"https://api.github.com/repos/phoenixframework/phoenix/issues/comments/93021676","html_url":"https://github.com/phoenixframework/phoenix/issues/767#issuecomment-93021676","issue_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/767","id":93021676,"user":{"login":"duijf","id":1123589,"avatar_url":"https://avatars.githubusercontent.com/u/1123589?v=3","gravatar_id":"","url":"https://api.github.com/users/duijf","html_url":"https://github.com/duijf","followers_url":"https://api.github.com/users/duijf/followers","following_url":"https://api.github.com/users/duijf/following{/other_user}","gists_url":"https://api.github.com/users/duijf/gists{/gist_id}","starred_url":"https://api.github.com/users/duijf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duijf/subscriptions","organizations_url":"https://api.github.com/users/duijf/orgs","repos_url":"https://api.github.com/users/duijf/repos","events_url":"https://api.github.com/users/duijf/events{/privacy}","received_events_url":"https://api.github.com/users/duijf/received_events","type":"User","site_admin":false},"created_at":"2015-04-14T19:04:28Z","updated_at":"2015-04-14T19:04:28Z","body":"Hi all,\r\n\r\nNew here, but I'd love to try and implement this tomorrow if it isn't already taken :)"}}