Introducci贸n

1

Pasos para construir aplicaciones en Ruby on Rails

2

Retomando nuestro proyecto

3

Instalando MongoDB

4

Migrando nuestra aplicaci贸n: componentes, librer铆as y configuraciones

5

Migrando nuestra aplicaci贸n: modelos

6

Migrando nuestra aplicaci贸n: modelos restantes y seeds

Pruebas

7

驴Qu茅 es TDD y BDD?

8

Construyendo nuestra f谩brica de documentos de prueba

9

Esteroides para tus pruebas

10

A帽adiendo pruebas de modelo

11

A帽adiendo pruebas de modelo: validaci贸n de datos

12

Finalizando las pruebas de modelo

13

A帽adiendo pruebas de peticiones

14

Creando y probando tareas de petici贸n

15

Headless browser

16

A帽adiendo pruebas de sistema: interacci贸n del sistema

17

A帽adiendo pruebas de sistema: comportamientos din谩micos

Interacci贸n din谩mica

18

Rails con caf茅

19

Selectize, esteroides para tus selects

20

Retomando los formularios anidados

21

Mejorando la asignaci贸n de participantes

Notificaciones

22

Retomando las notificaciones del proyecto

23

Introducci贸n a Service Objects

24

Construyendo prueba de servicio de notificaci贸n por correo

25

Construyendo servicio de notificaci贸n por correo

26

Introducci贸n a procesos en background y Active Job

27

Creando un Job para la notificaci贸n de correo

Ciclos de vida

28

Introducci贸n a m谩quinas de estado

29

Creando m谩quina de estados para la tarea

30

Creando servicio de gesti贸n de estados de la tarea

31

Actualizando estados usando eventos

32

Modificando estados desde la interfaz

Cierre

33

Optimizaciones: fundamentos

34

Conclusiones

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
12 Hrs
42 Min
25 Seg

A帽adiendo pruebas de peticiones

13/34
Resources

How to design integration tests for a Rails model?

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.

What tools do we need for request testing?

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:

  1. Add the required gem:

    • Include the gem inside the test group in your gemfile:
      group :test do gem 'rails-controller-testing'end
  2. Install the gem: Run the following command in your terminal to install the gem:

    bundle install
  3. Generate the basic structure of the test:

    • Use the RSpec generator to create the request test:
      rails generate rspec:request tasks

How to run the initial test?

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.

How to handle authentication during testing?

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:

  1. Configure integration helpers:

    • Modify the test configuration in the rails_helper file:
      RSpec.configure do |config| config.include Devise::Test::IntegrationHelpers, type: :requestend
  2. Log in before each test:

    • Create a user and use a helper to simulate logon:
      before(:each) do user = FactoryBot.create(:user) sign_in userend

How to formulate concrete requests to specific paths?

Once authentication is assured, you can proceed by simply testing access to defined paths:

get new_task_pathexpect(response).to render_template(:new)

How to improve the testing experience?

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.

Next steps and recommendations

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.

  • Delve deeper into sending specific parameters in your requests.
  • Explore using more RSpec helpers to refine your test suite.

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

Sort by:

Want to see more contributions, questions and answers from the community?

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