ExMachina 2.0 - Cast Away

Josh Steiner

ExMachina is a library for creating test data in Elixir. We’ve made a number of improvements and bug fixes since 1.0. Read on for notable changes, or checkout the CHANGELOG for a full list of changes.

Automatic Casting

The biggest change in ExMachina 2.0 is the automatic casting of values on insert. Now, instead of having to cast dates or decimals manually, you can let ExMachina do the dirty work for you. Consider this schema:

schema "items" do
  field :price, :decimal

In ExMachina 1.0, you’d have to set the price as a Decimal manually:

insert(:item, price: Decimal.new(100))
# => %Item{price: #Decimal<100>}

In ExMachina 2.0, you can pass the uncast value as you would in Ecto, and ExMachina will handle casting for you:

insert(:item, price: 100)
# => %Item{price: #Decimal<100>}

params_* improvements

Thanks to pdawczak for contributing a new function string_params_for, which is handy for generating params in controller test. We’ve also made some changes to the params family of functions, to better handle nil values and associations.

Upgrading to ExMachina 2.0

Due to changes with the params functions, there may be some breakage in upgrading. See the CHANGELOG for more details about what’s changed.

Thanks to our contributors

As always, thanks to all of our contributors, who make open source software possible!