3

I want to test below organizer interactor for, calling the 2 specified interactors without executing the calling interactors('SaveRecord, PushToService') code.

class Create
  include Interactor::Organizer

  organize SaveRecord, PushToService
end

I found few examples where the overall result of all the interactors logic(record should be saved and pushed to other service) has been tested. But, i dont want to execute the other interactor's logic as they will be tested as part of their separate specs.

1. Is it possible to do so?
2. Which way of testing(testing the overall result/testing only this particular 
   organizer interactor behavior) is a better practise?
4

2 回答 2

6

我相信我们需要在不执行包含的交互器的情况下测试包含的交互器的交互器组织者。我能够找到一种方法存根并用以下几行测试组织者

存根:

  allow(SaveRecord).to receive(:call!) { :success }
  allow(PushToService).to receive(:call!) { :success }

去测试:

it { expect(interactor).to be_kind_of(Interactor::Organizer) }
it { expect(described_class.organized).to eq([SaveRecord, PushToService]) }

call! method & organized variable从试图在内部调用和使用的交互器管理器源文件中找到。存根call!方法并测试organized变量已满足我的要求。

于 2017-05-17T15:27:54.320 回答
2

您可以测试它们被调用的顺序:

it 'calls the interactors' do
  expect(SaveRecord).to receive(:call!).ordered
  expect(PushToService).to receive(:call!).ordered
  described_class.call
end

请参阅:https ://relishapp.com/rspec/rspec-mocks/docs/setting-constraints/message-order

于 2020-10-27T04:30:34.560 回答