Introducci贸n
Pasos para construir aplicaciones en Ruby on Rails
Retomando nuestro proyecto
Instalando MongoDB
Migrando nuestra aplicaci贸n: componentes, librer铆as y configuraciones
Migrando nuestra aplicaci贸n: modelos
Migrando nuestra aplicaci贸n: modelos restantes y seeds
Pruebas
驴Qu茅 es TDD y BDD?
Construyendo nuestra f谩brica de documentos de prueba
Esteroides para tus pruebas
A帽adiendo pruebas de modelo
A帽adiendo pruebas de modelo: validaci贸n de datos
Finalizando las pruebas de modelo
A帽adiendo pruebas de peticiones
Creando y probando tareas de petici贸n
Headless browser
A帽adiendo pruebas de sistema: interacci贸n del sistema
A帽adiendo pruebas de sistema: comportamientos din谩micos
Interacci贸n din谩mica
Rails con caf茅
Selectize, esteroides para tus selects
Retomando los formularios anidados
Mejorando la asignaci贸n de participantes
Notificaciones
Retomando las notificaciones del proyecto
Introducci贸n a Service Objects
Construyendo prueba de servicio de notificaci贸n por correo
Construyendo servicio de notificaci贸n por correo
Introducci贸n a procesos en background y Active Job
Creando un Job para la notificaci贸n de correo
Ciclos de vida
Introducci贸n a m谩quinas de estado
Creando m谩quina de estados para la tarea
Creando servicio de gesti贸n de estados de la tarea
Actualizando estados usando eventos
Modificando estados desde la interfaz
Cierre
Optimizaciones: fundamentos
Conclusiones
You don't have access to this class
Keep learning! Join and start boosting your career
In the world of software development, having an automated testing environment is crucial to ensure the proper functioning of our applications before release. Below, I'll show you how to prepare your Rails environment to implement automated tests using some essential gems and appropriate configurations.
We'll start this process by integrating several gems that will be critical to our tests. First, we need to modify our Gemfile
and create a new gem group exclusively for automated testing. Be sure not to use the shared group between testing and development, as these gems must be specific for this purpose.
Database Cleaner: This gem is essential for keeping the database clean and in a consistent state between tests. Although MongoDB has started to implement transactional functionality, it is still advisable to use this resource to ensure that each test starts with clean and consistent data.
Faker: This gem is useful for generating dummy data such as names, emails and more, without additional effort. This is especially useful when you need test data populations.
Capybara: Although it will not be used immediately, Capybara will be useful when working with graphical or browser interaction tests. When we reach this point, I will explain its implementation more in depth.
The integration of RSpec and FactoryBot is fundamental in this process. Here's how to do it:
RSpec Rails: Although RSpec is not fully tied to Rails, it is necessary to use the rspec-rails
gem to properly integrate it into our project.
FactoryBot: This tool allows us to create model instances quickly and automatically. You must include the factory_bot_rails
gem to associate it properly in your Rails project.
After installing these gems, the next step is to make additional configurations in the help files generated by RSpec:
Spec Helper: Here, you can define filters and formatting that determine the execution and reporting behavior of your tests. Be sure to enable the filter_run_when_matching :focus
to run specific tests and set the default_formatter = 'doc'
to get detailed results.
Rails Helper: In this file, import each of the installed libraries and set specific configurations, such as disabling default transactions for MongoDB and configuring helpers for FactoryBot and authentication devices.
Database Cleaner optimization is achieved by defining specific callbacks for database cleaning before and after each test suite or individual test. In this way, you ensure that no test interferes with another, maintaining the integrity of the environment.
Before the test suite: Define the ORM you will use (Mongoid) and clean up the database to start with a uniform environment.
Before and after each test: Configure the initialization and cleanup of the database state respecting the unique context for each test.
Finally, make sure to properly configure test type inference and error handling using the following lines in your rails_helper.rb
file:
Infer Spec Type from File Location: Facilitates the use of test type-specific methods based on the file location.
Filter Rails from Backtraces: Hides trace lines not relevant to the developer and related to the Rails core.
These initial configurations are essential to prepare a robust testing environment to ensure the reliability and consistency of your Rails applications. Be encouraged to continue learning and perfect your automated testing skills!
Contributions 1
Questions 1
Want to see more contributions, questions and answers from the community?