stubby v0.2.0 Stubby
Usage
Start by defining your Behaviour:
defmodule Api do
@callback all() :: {:ok, term} | {:error, String.t}
@callback get(term) :: {:ok, term} | {:error, String.t}
...
end
Once a behaviour is defined, define your stub, using Stubby for one or more behaviours:
defmodule StubApi do
use Stubby, for: [Api, SomeOtherBehaviour]
end
In your tests, simply call your stubs generated setup/0 function:
StubApi.setup
Once setup/0 has been called, your stub will have a stub/2 function that takes in the function name you intend to stub as an atom and an anonymous function whose arity must match that of the stubbed function:
StubApi.stub(:all, fn -> {:ok, "Awesome!"} end)