Skip to content

simble-app/tacos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tacos

A fixture library for Elixir

Features

  • JSON fixutre support
  • YAML fixture support
  • Mix task for generating (empty) fixtures from Ecto models

Instructions

Installation

Add to your mix.exs

{:tacos, github: "simble-app/tacos", tag: "v0.0.1"}

Setup

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.

Usage

Tacos#tacos

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]]])

Mix Tasks

Initial Setup

Create the default directories for tacos (tacos/data and tacos/test)

$ mix tacos.setup

Ecto and/or Vex Integration

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

Misc

Known Limitations Issues

  • 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.

Possible Features

  • JSON-Schema support
  • Rich fixture generation from JSON-Schema support

Why?

  1. There aren't any other fixture libraries for Elixir
  2. It seemed easy enough to do? ¯\(ツ)
  3. I don't like factories, nay... I hate factories
  4. Community profit?
  5. Tacos are delicious

Pull Requests

  1. Pull requests must pass tests and add full coverage.
  2. You only need to add coverage to publicly available methods.

License

Tacos is released under the MIT License.

About

A fixture library for Elixir

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages