Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
RSpec match_array con hashes

Me preguntaba si hay una manera de lograr lo que quiero con RSpec. Así que quiero probar una matriz de hash que se parezca a esta:

 array_example = [ { id: 1, link: "www.some-link.com/path_im_not_interested_in" }, { id: 2, link: "www.example-link.com/another_useless_path" } ]

Quiero hacer una prueba de integración en la que no incluiré esas rutas en los enlaces. Solo me interesa verificar si www.some-link.com y www.example-link.com están presentes en esos hashes en la matriz. Algo como esto:

 expect(array_example).to match_array( [ { id: 1, link: "www.some-link.com" }, { id: 2, link: "www.example-link.com" } ]

Pero este obviamente no funcionará. ¿Hay alguna manera de lograr lo que quiero? Me gustaría evitar el uso de emparejadores personalizados.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puedes usar emparejadores compuestos:

 expect(array_example) .to contain_exactly( a_hash_including(id: 1, link: a_string_including("www.some-link.com")), a_hash_including(id: 2, link: a_string_including("www.example-link.com")) )

Consulte https://rspec.info/blog/2014/01/new-in-rspec-3-composable-matchers/ para obtener más información.

El argumento de a_hash_including no tiene que cubrir todo el hash, solo verificará las claves que está pasando.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!