vendredi 5 mars 2021

RSpec: Can we configure an expectation to return two different value? I want to test retry mechanism

So I have a retry rule in my application. I wanted to test that using rspec.

When I call service without passing account ID it should give me false and when account ID is passed it should give me true.

I am trying this code

options = {
  email: 'dev@dev.com'
}
expect_any_instance_of(PaymentService::CreatePayment).to receive(:call)
                                                           .with(options)
                                                           .and_return(false)
options[:account_id] = 12345
expect_any_instance_of(PaymentService::CreatePayment).to receive(:call)
                                                           .with(options)
                                                           .and_return(true)

But this doesnt work for me.

Aucun commentaire:

Enregistrer un commentaire