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 Nested Contexts

When you’re working with a bare-bones testing framework like ExUnit, you’ll experience significant repetition when you set up code. Consider this testing script:

  ...
 
 setup context ​do
  set_up_web_app
 end
 
 test ​"​​index, logged in"​ ​do
  user = new_user context
  log_in user
 
  response = get(​"​​/"​)
  assert response.code == 200
  assert response.template == ​"​​index"
 end
 
 test ​"​​profile, logged in"​ ​do
  user = new_user context
  log_in user
 
  response = get(​"​​/​​#{​user.id​}​​"​)
  assert response.code == 200
  assert response.template == ​"​​profile"
 end
 
 test ​"​​profile, logged out"​ ​do
  response = get(​"​​/"​)
  assert response.code == 404
 end ...

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