export RUBYOPT='-W:no-deprecated -W:no-experimental'
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
Integration tests are essential to verify that the different components of an application work together correctly. To achieve this in a Rails application, we will use the model task
as our main testing tool. In addition, we will take advantage of gems and tools that facilitate this process. This article will walk you through the process of setting up and running a request test in Rails.
Before you start, you need to prepare your working environment and make sure you have everything you need to run the tests. I provide you with a list of steps to follow:
Add the required gem:
gemfile
:group :test do gem 'rails-controller-testing'end
Install the gem: Run the following command in your terminal to install the gem:
bundle install
Generate the basic structure of the test:
RSpec
generator to create the request test:rails generate rspec:request tasks
Once we have prepared the structural base for the tests, we need to verify that the initial setup works properly. To do that, run the tests with the following command in the console:
rspec
If you receive an HTTP 302
status instead of 200
, it could mean an erroneous redirect, suggesting that the request requires authentication.
For tests that require authentication, it is important to ensure that the user is authenticated before launching the tests. Devices such as Device
already provide useful helpers for this purpose:
Configure integration helpers:
rails_helper
file:RSpec.configure do |config| config.include Devise::Test::IntegrationHelpers, type: :requestend
Log in before each test:
before(:each) do user = FactoryBot.create(:user) sign_in userend
Once authentication is assured, you can proceed by simply testing access to defined paths:
get new_task_pathexpect(response).to render_template(:new)
When performing integration tests, it is common to encounter warning messages about future version changes. If you want to hide these messages, you can adjust the environment variables:
export RUBYOPT='-W0'rspec
With these steps, we reduce visual noise and improve readability when running tests.
Now that you've learned how to run basic request tests and address authentication issues, you're ready to continue exploring more complex types of tests.
Continuous learning and constant practice are essential on the road to software development. Follow this path, and you will see your skills get stronger every day.
Contributions 3
Questions 0
export RUBYOPT='-W:no-deprecated -W:no-experimental'
Configuraci贸n de Variable de Entorno para ignorar deplacation warning
Configuraci贸n de Variable de Entorno para ignorar deplacation warning
Want to see more contributions, questions and answers from the community?