What We Should Test With RSpec in Rails

Well, what is takes to begin testing Rails applications. The hardest part of being a beginner is that you often don’t know what you should test with RSpec in Rails.

Here is the most important thing is that you are testing: Feature specs, Model specs, Controller specs, View specs, Route specs.

Feature specs
Feature specs is a kind of acceptance test, the tests that walk through your entire application ensuring that each of the components work together.
They are written from the perspective of a user clicking around the application and filling in forms on the page.
While Feature specs are great for testing high level functionality, keep in mind that feature specs is slow to run.

Model specs
Model specs are similar to unit tests in that they are used to test smaller parts of the system, such as classes or methods, and they interact with the database too.

Controller specs
When testing multiple paths through a controller is necessary, we favor using controller specs over feature specs, as they are faster to run and often easier to write.

View specs
View specs is great for testing the conditional display of information in the templates. Most developers forget about these tests and use feature specs instead.
While you can cover each view conditional with a feature specs, I prefer to user view specs.

Route specs
Most Ruby on Rails developers don’t test their routes, If you ever need to test an abstract base controller independently from any subclass, you will like need to add route specs for your testing.

So far so good, this was just an overview of what we should get started testing Rails. :)