Muy buena clase. En general este curso me encanta, el profesor hace que rspec sea muy sencillo de entender y utilizar.
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 software development, ensuring that a model works correctly is essential. Testing not only ensures functionality, but also validates the persistence and ownership of the model. In this class, we focus on testing models using methods and validations in Ruby on Rails.
To ensure that a model is correctly saved and validated, it is essential to create a specific context. A nested context is an effective way to separate different test scenarios.
with Parance from Scratch
to define a context.before Each
method to invoke save
before each test.Code example:
'with Parance from Scratch' context do before(:each) do @task.save endend end
After invoking save
, it is important to validate two main aspects of the model:
be_persisted
to confirm that the model is saved.be_present
.Example code:
expect(@task).to be_persistedexpect(@task.code).to be_present.
A common scenario is to verify that past dates are not valid for the model. For this, you can create a specific context and use the tap
function to modify the attributes of the model.
with due date in the past
.tap
method to directly modify the due_date
attribute.Example code:
context 'with due date in the past' do before(:each) do @task.tap do |t| t.due_date = Date.today - 1 end end end it 'is expected not to be valid' do expect(@task).not_to be_valid endend end end
Running the tests and checking that they fail correctly when the date is earlier than the current date is a crucial step for robust model checking. Tools such as rspec
facilitate this process with quick commands.
Now, having accomplished the necessary validations and ensured the correct functioning of the model, it is suggested that you try applying the same techniques to other models as a user
. The concepts of persistence, validation and modification of internal attributes will be equally applicable. As you progress, you will encounter HTTP requests which we will cover in the next class. So don't give up, keep going with curiosity and determination.
Contributions 1
Questions 0
Muy buena clase. En general este curso me encanta, el profesor hace que rspec sea muy sencillo de entender y utilizar.
Want to see more contributions, questions and answers from the community?