Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/malomohq/tock
Mock remote function calls made by Task.Supervisor in Elixir
https://github.com/malomohq/tock
elixir-lang made-by-malomo otp
Last synced: 3 days ago
JSON representation
Mock remote function calls made by Task.Supervisor in Elixir
- Host: GitHub
- URL: https://github.com/malomohq/tock
- Owner: malomohq
- License: mit
- Created: 2020-04-02T14:51:11.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-08T20:53:14.000Z (almost 5 years ago)
- Last Synced: 2025-01-01T14:48:04.373Z (19 days ago)
- Topics: elixir-lang, made-by-malomo, otp
- Language: Elixir
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tock
Tock is a library for mocking remote function calls made by `Task.Supervisor`.
## Installation
Just add `tock` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{ :tock, "~> 1.0", only: :test }
]
end
```## Usage
When working in a distributed system `Task.Supervisor` provides a mechanism
for calling functions on a remote node.```elixir
{ MyRemoteTaskSupervisor, remote_node }
|> Task.Supervisor.async(MyRemoteModule, :add, [2, 3])
|> Task.await()
```Tock allows you to easily mock a remote application. This eliminates the need to
mock your own code. Instead, mock the behavior of an application running on a
remote node.```elixir
use ExUnit.Case, async: truetest "invokes add on a remote node" do
MyRemoteTaskSupervisor
|> Tock.start()
|> Tock.expect(MyRemoteMod, :add, fn(x, y) -> x + y end)assert { MyRemoteTaskSupervisor, node() }
|> Task.Supervisor.async(MyRemoteModule, :add, [2, 3])
|> Task.await() == 5
end
```All expectations are defined based on the current process. This allows
multiple tests to run concurrently when using the same named
`Task.Supervisor`.