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

Condense and Combine the Measurements

We can still do better. In the previous test, we have only one measurement. Typically, we’ll have more than one. When that happens, our verify block can group several different measurements together, like this:

 defmodule​ AppTest ​do
 use​ ExUnit.Case
 use​ TrueStory
 
 use​ ExUnit.Case
 use​ TrueStory
 
 def​ set_map_key(c) ​do
  Map.put ​:setup​, ​:done
 end
 
 def​ set_second_key(c) ​do
  Map.put ​:test​, ​:true_story
 end
 
  story ​"​​two context keys"​, c
  |> set_map_key
  |> set_second_key,
  verify ​do
  assert ​:setup​ ​in​ Map.keys(c)
  assert ​:test​ ​in​ Map.keys(c)
  refute ​:not_present​ ​in​ Map.keys(c)
 end
 end

The grouping is an improvement. It does two ...

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