Testing Models with RSpec in a Rails Application
In this lesson, we are going to create a sample user model for RSpec testing. This will give us a model to work with and build in some tests for behavior.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this lesson, we are going to create a sample user model for RSpec testing. This will give us a model to work with and build in some tests for behavior.

Just to let you know the method we're going to follow is not the right way to create a user interface, but since this is just a test for Rspec, I'm doing it in a simplified way.
To create a user model, the code is:

rails g model User name:string email:string password:string

In the real world, we'll encrypt our passwords, but we're not doing it here because it's only an example.

large

Next, let's run this command:

bundle exec rake db:migrate

This command will give us access to this new user model.

large

Let's just check if this working, and to do this, open the rails console with the command: rails c

Then, run User.all, and there is no error!

In the next few lessons we'll start integrating tests for our new User model.