我想测试下面的管理器交互器,调用 2 个指定的交互器而不执行调用交互器('SaveRecord,PushToService')代码。
class Create
include Interactor::Organizer
organize SaveRecord, PushToService
end
我发现了几个例子,其中所有交互器逻辑的整体结果(记录应该保存并推送到其他服务)已经过测试。但是,我不想执行其他交互者的逻辑,因为它们将作为其单独规范的一部分进行测试。
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?
最佳答案
我相信我们需要在不执行包含的 interacor 的情况下测试包含的交互器的交互器管理器。我能够找到一种方法 stub 并使用以下几行测试组织者
到 stub :
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]) }
找到调用!方法和组织变量
来自它试图在内部调用和使用的交互器管理器源文件。 stub call!
方法并测试 organized
变量已满足我的要求。
关于ruby-on-rails - 我们如何使用 rspec 测试交互组织者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43984783/