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

367
Views
¿Cómo me burlo de un argumento de bloque en RSpec?

Digamos que estoy llamando a un método Ruby con un argumento de bloque en Ruby:

 Net::SFTP.start('testhost.com', 'test_user', keys: ['key']) do |sftp| sftp.upload!('/local', '/remote') end

¿Cómo puedo probar que la upload! se llamó al método con los argumentos correctos?

Podría llegar tan lejos, probando los argumentos para #start ,

 expect(Net::SFTP). to receive(:start) do |host, username, keyword_args, &block| expect(host).to eq("testhost.com") expect(username).to eq("test_user") expect(keyword_args).to eq(keys: ["test_key"]) end

¡Pero no sé cómo probar esa #upload! fue llamado en el bloque.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Utilice and_yield : funciona mejor cuando se combina con allow().to receive y have_received matcher:

 sftp = spy allow(Net::SFTP).to receive(:start).and_yield(sftp) # execute your code here expect(Net::SFTP).to have_received(:start).with("testhost.com", "test_user", keys: ["test_key"]) expect(sftp).to have_received(:upload!).with('./local', '/remote')
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!