Skip to content

Instantly share code, notes, and snippets.

@imranismail
Created October 31, 2015 09:38
Show Gist options
  • Save imranismail/a156fc233f01b4a69a21 to your computer and use it in GitHub Desktop.
Save imranismail/a156fc233f01b4a69a21 to your computer and use it in GitHub Desktop.
Sharing context across tests
defmodule KeyVal.RegistryTest do
use ExUnit.Case, async: false
setup do
{:ok, registry} = KeyVal.Registry.start_link
{:ok, registry: registry}
end
test "spawns bucket", %{registry: registry} do
assert {:ok, _bucket} = KeyVal.Registry.create(registry, "shopping")
assert KeyVal.Registry.create(registry, "shopping") == :error
end
test "can lookup for a bucket", %{registry: registry} do
assert {:ok, bucket} = KeyVal.Registry.lookup(registry, "shopping")
end
test "can store value in spawned bucket", %{registry: registry} do
assert {:ok, bucket} = KeyVal.Registry.lookup(registry, "shopping")
KeyVal.Bucket.put(bucket, "eggs", 1)
assert KeyVal.Bucket.get(bucket, "eggs") == 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment