Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

Testing functions without side-effects

A unit test exercises a function from a certain module of the application. We might have more than one test exercising the same function (with different inputs, for instance). Let's begin by creating a simple test, which will allow us to analyze ExUnit in detail. We'll be creating the tests for the is_valid_path? function, which belongs to the ElixirDrip.Storage.Media module. For context, we present its implementation as follows:

$ cat apps/elixir_drip/lib/elixir_drip/storage/media.exdefmodule ElixirDrip.Storage.Media do  # ...  def is_valid_path?(path) when is_binary(path) do    valid? = String.starts_with?(path, "$") && !String.ends_with?    (path, "/")    case valid? do      true -> {:ok, :valid} false -> {:error, ...
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

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content