Current section

Files

Jump to
stitch README.md
Raw

README.md

# Stitch
![Hex.pm Version](https://img.shields.io/hexpm/v/stitch?style=flat&link=https%3A%2F%2Fhex.pm%2Fpackages%2Fstitch)
[![builds.sr.ht status](https://builds.sr.ht/~nomorepanic/stitch/commits/main/test-current.yaml.svg)](https://builds.sr.ht/~nomorepanic/stitch/commits/main/test-current.yaml?)
Easy mocking for easy testing.
## Instructions
It's as simple as:
```elixir
defmodule SomeTest do
import Stitch
test "calling IO.puts" do
stitch IO, ["puts"] do
result = Mymodule.func("pandoro")
# Assume func = fn x -> IO.puts(x) end
assert called(IO.puts("pandoro"))
assert result == "puts/1"
end
end
end
```
If you need a specific value:
```elixir
test "calling IO.puts" do
stitch IO, [{"puts/1", :value}] do
result = Mymodule.func("pandoro")
assert called(IO.puts("pandoro"))
assert result == :value
end
end
```