Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

366
Vistas
Rspec: How to test efficiently a method for each day of the year?

I'm currently using rspec in a ruby on rails project, to test a method in a model.

In my case, I have a #set_season method which returns the season based on the current_date. So I expect this method to never return nil.

My test is passing just fine, but this seems a very ugly way to do it. I just can't see any other solution for now. But I'm trying to improve my testing skills AND the performance of the codebase that I'm testing. So any help of you girls&guys is welcome 🙏

    describe '#set_season' do
      it 'is never nil' do
        (1..12).each do |month|
          (1..31).each do |day|
            promotion.update(start_date: Time.new(2021, month, day))
            promotion.set_season
            expect(promotion.season).not_to be_nil
          end
        end
      end
    end

Thanks !

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Just to close this subject, I decided to keep testing my method for each day of the year, and improved my loop with a (Date.today..Date.today + 1.year) as suggested.

describe '#set_season' do
  it 'is never nil' do
    (Date.today..Date.today + 1.year).each do |date|
      promotion.update(start_date: date)
      promotion.set_season
      expect(promotion.season).not_to be_nil
     end
  end
end
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda