/exchema_stream_data

Primary LanguageElixirOtherNOASSERTION

ExchemaStreamData

This helps you generate test data for property testing if you are using stream_data and exchema

You would do something like

  property "types are valid" do
    check all value <- ExchemaStreamData.gen(MyExchemaType) do
      assert Exchema.is?(value, MyExchemaType)
    end
  end

Overriding generators

ExchemaStreamData.gen(MyType, &overrides/2)

def overrides(type, original) do
  case type do
    MyType ->
      StreamData.constant(10)
    Exchema.Types.Integer.Positive ->
      # Will return only `10, 20, 30, 40, ...`
      StreamData.map(original, &(&1*10))
    _ ->
      original
  end
end

Installation

If available in Hex, the package can be installed by adding exchema_stream_data to your list of dependencies in mix.exs:

def deps do
  [
    {:exchema_stream_data, "~> 0.1.0", only: [:test]}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exchema_stream_data.

TODO

  • Generate for all exchema base types
  • Allow to override generation for a specific type (useful for custom types or types with a lot of refinements)