Latest August of this year I started to learn Rails. I was following the book from website which uses Minitest to test their application. Truth is: So I decided to skip them and try to write it using RSpec because the syntax is way more similar to human language than others. But you may be wondering: Ruby on Rails Tutorial Learn Enough To Be Dangerous I was not understanding a single line of code about those tests. Why should I write tests when I'm just learning something new? Well, despite the fact that this is a must-have skill for developers, writing tests help you to make sure that your code is producing the results you expect. So that being said, let's start coding! Setting up Rails App First of all, let's create our new Rails App, type in your terminal: rails app_for_test -T new The command -T is to skip the generation of files and folders, which is exactly what we want because we're going to use RSpec to test our application instead of the default. Test::Unit Now go to your gemfile and add the RSpec gem in the development, test group: group , gem :development :test do 'rspec-rails' end Note: if you're using Rails 6 you need to write: rspec-rails ~> . .beta2 'gem ' ', ' 4.0 0 ' Then in your terminal run the command: install bundle To set up RSpec in your app and create the Spec folder run: rails rspec:install generate Let's start with our model. I'll create a simple Movie table that has a title, director and rate: rails model Movie title: director: rate: generate string string integer Then: rails db :migrate Now you should have the following file in your app: spec/models/movie_spec.rb Following the TDD( ) principles, we're going to build our tests and then write the code. Let's think about what kind of tests we need for Model: Test Driven Development Title, director and rate needs to be present Title and director needs a minimum and maximun length Rate should be a integer between 1 - 10 In your you will see the RSpec block where you will write your tests inside it: spec/model/movie_spec.rb RSpec.describe Movie, type: :model do #tests go here end Now we will create it blocks for each behaviour we're expecting in the Movie's model. So remember to be as clear as possible when describe your tests because you need to be a good communicator and make yourself understandable not only with computers but also with people. You may be wondering why did I upload an image, right? Well, it was on purpose so this way you will have to actually write the code instead of just copy and past and that will be really good for your muscle memory and practice with eventual typos. Now to run your tests, type in your terminal: rspec The command above will run all the tests available in your entire app. When you want to run tests only in some specific files you can type: rspec spec file_spec.rb /some_folder/ That format in our application would be: rspec spec ovie_spec.rb /models/m We just have one test file in this app so both commands will get you the same results, which in our case is: and this makes sense because if you pay attention in what we expect in the tests you'll see that none of them should be valid and all of that are being valid now because we have our model's validations completely empty. 8 examples, 8 failures Now let's write the necessary validations to make our tests green! In your write the following lines: app/models/movie.rb, validates , , { .. } validates , , { .. } validates , , { .. }, { } :title presence: true length: in: 6 25 :director presence: true length: in: 5 20 :rate presence: true length: in: 1 10 numericality: only_integer: true Now run rspec again in your terminal: rspec You should get: . 8 examples, 0 failures And... That's it! You just wrote your first tests using RSpec. So if you want to keep going try to write some specs for Movies' controller now and when you feel confident with those you can search and learn how to use and to write more complex tests. You can check out this to get some ideas. Capybara, FactorbyBot, Faker repository Good luck with your journey and HAPPY CODING!!!