Skip to Main Content
Programming Phoenix
book

Programming Phoenix

by Chris McCord, Bruce Tate, Jose Valim
April 2016
Beginner to intermediate content levelBeginner to intermediate
300 pages
6h 58m
English
Pragmatic Bookshelf
Content preview from Programming Phoenix

Unit-Testing Plugs

If your code is worth writing, it’s worth testing. Earlier, we bypassed our authentication plug, so we should test it now. The good news is that since our plug is essentially a function, it’s relatively easy to build a set of tests that will confirm that it does what we need.

Create a test/controllers/auth_test.exs and key in the following contents. We’re going to break the test file into parts to keep things simple.

First, test the authenticate_user function that does the lion’s share of the work:

 defmodule​ Rumbl.AuthTest ​do
 use​ Rumbl.ConnCase
  alias Rumbl.Auth
 
  test ​"​​authenticate_user halts when no current_user exists"​,
  %{​conn:​ conn} ​do
 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Elm

Programming Elm

Jeremy Fairbank
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781680501926Errata Page