Rails: How to setup rspec on Rails
Table of contents
Add
rspec
to the Gemfile;group :development, :test do gem 'rspec-rails' end
Install the dependencies
bundle install
Check if it was installed correctly
gem list rspec
You should see something like this
Check version
Install rspec
rails generate rspec:install
You should see something like this
Generate a rspec model
rails generate rspec:model Product
Product
is a model. This is just an example.Destroy a rspec model (Just in case you need it)
rails destroy rspec:model Product
Run a specific test on a single file
rspec spec/models/product_spec.rb:3
In this example, the test starts in line 3.
You should see something like this
Run the tests for a single file
rspec spec/models/product_spec.rb
You should see something like this
Run all tests
rspec spec
You should see something like this
Celebrate! It's working.
Conclusion
In this article, we learned how to setup Rspec on Rails.
Let me know if you need any additional help.