Giter VIP home page Giter VIP logo

specimen's Introduction

Specimen

๐Ÿญ A reasonable factory implementation structure for elixir applications.

Installation

If available in Hex, the package can be installed by adding specimen to your list of dependencies in mix.exs or pulling the dependencies directly from Github:

def deps do
  [
    {:specimen, github: "jankensoft/specimen"}
  ]
end

Basic Usage

defmodule UserFactory do
  use Specimen.Factory, module: User

  def build(specimen) do
    specimen
    |> Specimen.include(:name, "John")
    |> Specimen.include(:age, 42)
  end

  def state(:lastname, %User{} = user) do
    Map.put(user, :lastname, "Doe")
  end
end

Making and inserting just one user

UserFactory.make_one()
#=> %Specimen.Context{struct: %User{}}

UserFactory.create_one()
#=> %Specimen.Context{struct: %User{}}

Making and inserting a specific amount of users

UserFactory.make_many(10)
#=> [%Specimen.Context{struct: %User{}}, ...]

UserFactory.create_many(10)
#=> [%Specimen.Context{struct: %User{}}, ...]

Making and inserting a user with lastname

UserFactory.make_one([:lastname])
#=> %Specimen.Context{struct: %User{}}

UserFactory.create_one([:lastname])
#=> %Specimen.Context{struct: %User{}}

Retrieving data from the building context

Specimen.Context.get_struct(UserFactory.create_one()) 
#=> %User{}

Specimen.Context.get_struct(UserFactory.create_many(10)) 
#=> [%User{}, ...]

Calling factories from struct modules

defmodule User do
  use Specimen.HasFactory, UserFactory
  defstruct [:name, :surname, :age]
end
User.Factory.make_one()
User.Factory.make_many(10)

TODO List

  • Add support for more Ecto types (UUID, embeds, etc...)
  • Allow configuration of Repo globally through application settings
  • Allow extension of custom types through external implementations (specific domains)
  • See if we can enforce that a non-empty factory only builds items for the specified module
  • Take in consideration excluded and included fields before using Specimen.fill/1
  • Allow the configuration of default states to call per factory
  • Add support to sequences (sequencing values)
  • Add before_create callback to allow factories to pre-configure how to patch entries beforehand
  • Add before_make callback to allow factories to pre-configure how to patch items beforehand

specimen's People

Contributors

thiagomajesk avatar madili avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.