Unit Test: Format Validation
Let’s learn to write a unit test to implement a format constraint.
We'll cover the following...
We'll cover the following...
Defining the test
This unit test restricts the name
field to only contain letters and spaces. To define this one, we’ll set a name containing an emoji character on the user and assert validation failure.
Here’s the test:
Press + to interact
context "when the name contains emojis" doit "the user is invalid" douser = User.new(name: "Hi 🤨")user.valid?expect(user.errors.messages).to include(:name)endend
Add the ...