Skip to content

Instantly share code, notes, and snippets.

@TylerPachal
Created February 11, 2020 20:58
Show Gist options
  • Save TylerPachal/5f6c014ab05e45f9017de42bff857a6d to your computer and use it in GitHub Desktop.
Save TylerPachal/5f6c014ab05e45f9017de42bff857a6d to your computer and use it in GitHub Desktop.
test "age is required" do
# Create changeset
params = %{"name" => "tyler"}
changset = Person.changeset(%Person{}, params)
# Changeset should be invalid
assert changeset.valid? == false
# Find the error message for the invalid field
error_message = Keyword.get(changeset.errors, :age)
# Make sure that the error message is useful and polite
assert error_message =~ "blank"
assert error_message =~ "please"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment