mix prop_schema.print (PropSchema v1.1.0) View Source
Usage:
mix prop_schema.print <module> [options]
Where module is the PropSchema module for which tests will be generated.
Options:
output_path Will output the results to a file at the given path. If file doesn't exist, it will be created additional_props A module where the custom properties you have written are found. Make sure the compiler will
actually compile the module for the dev environemnt.filters A module where the custom filters you have written are found. Make sure the compiler will
actually compile the module for the dev environemnt.Example
prop_schema "example" do
prop_field(:example_string, :string, string_type: :alphanumeric, required: true)
prop_field(:example_int, :integer, postive: true, required: false)
field(:example_float, :float)
endWill generate:
property("valid changeset") do
check(all(map <- StreamData.fixed_map([{"example_int", StreamData.one_of([StreamData.integer(), StreamData.constant(nil)])}, {"example_string", StreamData.string(:alphanumeric, min_length: 1)}]))) do
changeset = PropSchema.ExampleModule.changeset(struct(PropSchema.ExampleModule), map)
(fn changeset ->
if(not(changeset.valid?())) do
Logger.error("Test will fail because: #{inspect(changeset.errors())}")
end
assert(changeset.valid?())
end).(changeset)
end
property("valid changeset - missing example_int") do
check(all(map <- StreamData.fixed_map([{"example_string", StreamData.string(:alphanumeric, min_length: 1)}]))) do
changeset = PropSchema.ExampleModule.changeset(struct(PropSchema.ExampleModule), map)
(fn changeset ->
if(not(changeset.valid?())) do
Logger.error("Test will fail because: #{inspect(changeset.errors())}")
end
assert(changeset.valid?())
end).(changeset)
end
end
property("invalid changeset - missing example_string") do
check(all(map <- StreamData.fixed_map([{"example_int", StreamData.one_of([StreamData.integer(), StreamData.constant(nil)])}]))) do
changeset = PropSchema.ExampleModule.changeset(struct(PropSchema.ExampleModule), map)
(fn changeset ->
if(changeset.valid?()) do
Logger.error("Test will fail because: No errors")
end
refute(changeset.valid?())
end).(changeset)
end
end
Link to this section Summary
Functions
Callback implementation for Mix.Task.run/1.
Link to this section Functions
Callback implementation for Mix.Task.run/1.