A fixture library for Elixir
- JSON fixutre support
- YAML fixture support
- Mix task for generating (empty) fixtures from Ecto models
Add to your mix.exs
{:tacos, github: "simble-app/tacos", tag: "v0.0.1"}
Setup a directory for your tacos (fixtures). The default is test/tacos
$ mix tacos.setup
Optionally, you can configure tacos in your config/*.exs
files, configure where to find tacos.
# Ex. Configuration for the test environment
# config/test.exs
config :tacos, :tacos,
tacos_path: "tacos/test",
format: "json"
# Ex. All environments not "test"
# config/config.exs
config :tacos, :tacos,
tacos_path: "tacos/data",
format: "json"
If you do this, you'll need to generate tacos individually for each environment by setting MIX_ENV
.
Fairly straightforward, examples below are from the tests. Tacos tolerates string(s), atom(s), or keyword list with string, or atom, values.
# Fixtures can be retrieved one at a time
#
# tacos/test/spike.json
spike = Tacos.tacos("spike")
# Fixtures can be retrieved as a list
#
# tacos/test/spike.json
# tacos/test/faye.json
[spike, faye] = Tacos.tacos([:spike, :faye])
# Fixtures can be grouped (using directories)
#
# tacos/test/users/ein.json
[ein] = Tacos.tacos(users: :ein)
# Fixtures can be grouped (using directories)
#
# tacos/test/users/ein.json
# tacos/test/users/jet.json
[ein, jet] = Tacos.tacos(users: ["ein", "jet"])
# Fixtures can be deeply nested
#
# tacos/test/users/active/admin/ed.json
[edward] = Tacos.tacos(users: [active: [admin: [:ed]]])
Create the default directories for tacos (tacos/data
and tacos/test
)
$ mix tacos.setup
Tacos has a mix task to generate fixtures from Ecto models, or structs/maps using Vex [1,2].
# Simple
$ mix tacos.gen.model TheBebop.Crew
# Specify the base path (relative to the application root)
$ TACOS_PATH="delicious_tacos" mix tacos.gen.model TheBebop.Crew
1 It actually works with any struct (filters out :__struct__
) or map.
2 The reason it "works" with Ecto and/or Vex models is because it also filters out: :__meta__, :__id__, :inserted_at, :updated_at, :errors, :_vex
- No support for YAML fixture generation because I couldn't find an Elixir/Erlang libary to do (serialize) it.
- It automatically strips some keys, see Ecto/Vex Integration for specifics. If someone needs this configurable, create an issue or PR.
- JSON-Schema support
- Rich fixture generation from JSON-Schema support
- There aren't any other fixture libraries for Elixir
- It seemed easy enough to do? ¯\(ツ)/¯
- I don't like factories, nay... I hate factories
- Community profit?
- Tacos are delicious
- Pull requests must pass tests and add full coverage.
- You only need to add coverage to publicly available methods.
Tacos is released under the MIT License.