vendredi 13 novembre 2020

RSpec - Check if method was called further down(up?) the call stack

I've been using built-in Rails testing suite and am now moving into RSpec for testing. I'm trying to figure out to test if a method was called in the midst of calling another method. For example, my update_service.call method gets called with an object. The update_service calls the manage_service.call method. I'm trying to test that the manage_service.call method was ever called.

expect(@update_service).to receive(:call).with(object).at_least(:once)
expect(@manage_service).to receive(:call).with(object.id).at_least(:once)

@update_service.call(encounter)

With this setup, I get the following failure:

    Failures:

  1) UpdateService should call manage_service
     Failure/Error: expect(@manage_service).to receive(:call).with(object.id).at_least(:once)
     
       (#<ManageService:0x00007ffaf8c76190 @sdi=ServiceDI>).call(1)
           expected: at least 1 time with arguments: (1)
           received: 0 times
        # ....

I'm not sure what I'm missing here.

Aucun commentaire:

Enregistrer un commentaire