Writing the poll controller test

Since we're now experts on controller tests, let's start writing our poll controller test. Open up our test/vocial_web/controllers/poll_controller_test.exs file and let's write our first major test:

 test "GET /polls", %{conn: conn} do   conn = get conn, "/polls"   assert html_response(conn, 200) =~ "My First Poll" end

Then we'll run mix test and verify that our new test passes:

$ mix test.....Finished in 0.2 seconds5 tests, 0 failuresRandomized with seed 169967

Fantastic! Remember that in our dummy object, we gave the poll a title of "My First Poll", so that's why that test is structured the way it is! One habit you’ll want to get into, especially as you’re starting out, is slightly changing tests to make sure ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.