Unit Test: Maximum Length Constraint

Let’s learn to write a unit test to implement a maximum length constraint.

We'll cover the following

Defining the test

This test’s goal is to disallow more than 100 characters in the name field. Notice how we’re starting with the test. We’re describing the behavior we’d like to have, and only then do we implement it

Put the following test in the spec/models/user_spec.rb file.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy