Skip to content

Overview

Testing is a crucial part of the development process in a Rails application. It ensures that the code behaves as expected and helps in maintaining the quality of the application. In our Rails application, we use a combination of inbuilt Rails tests and RSpec for different types of tests.

Running Tests

To run the tests in our Rails application, you can use the following commands:

# Run all tests
rails test

# Run model tests
rails test:models

# Run controller tests
rails test:controllers

# Run RSpec tests
rspec

Test Strategy

  • Inbuilt Rails Tests for Models and Controllers: We use the inbuilt Rails testing framework for testing our models and some of the controllers. This helps in ensuring that the core functionalities of the application are working as expected.

  • Rswag-based RSpec for Some Controller Tests: For some of the controller tests, we use Rswag along with RSpec. Rswag helps in generating API documentation and testing the API endpoints.

  • Controller Test Conventions: We follow a few conventions for organizing our controller tests. Each controller has its own directory, and each method within the controller has its own test file. This helps in keeping the tests organized and easy to manage.