O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Controlling Setup Repetition with Story Pipes

We can eliminate this code in TrueStory with story pipes, like this:

  ...
 # this example is simplified for clarity
 
 def​ configure_web_app(c, ...) ​do
  c
  |> Map.put ​:conn​, set_up_test_conn(...)
 end
 
 def​ logged_in(c, user) ​do
  c
  |> Map.put ​:session​, log_in(new_user, c.conn)
 end
 def​ get_root(c) ​do
  c
  |> Map.put ​:response​, get_root(c.conn)
 end
 
  story ​"​​getting /"​, c
  |> configure_web_app
  |> get_root,
  verify ​do
  assert c.conn.response == ​:redirect
 # more assertions about an unauthorized get
 end
 
  story ​"​​getting /, logged in"​, c
  |> configure_web_app
  |> logged_in(create_user)
  |> get_root,
  verify ​do
  assert c.conn.response ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required