Pre*_*rem 3 rspec ruby-on-rails interactors
我想在组织者交互器下测试,调用 2 个指定的交互器而不执行调用交互器('SaveRecord,PushToService')代码。
class Create
include Interactor::Organizer
organize SaveRecord, PushToService
end
Run Code Online (Sandbox Code Playgroud)
我发现了几个例子,其中所有交互器逻辑的整体结果(记录应该被保存并推送到其他服务)已经过测试。但是,我不想执行其他交互器的逻辑,因为它们将作为其单独规范的一部分进行测试。
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?
Run Code Online (Sandbox Code Playgroud)
我相信我们需要在不执行包含的交互器的情况下测试包含交互器的交互器组织器。我能够找到一种方法存根并使用以下几行测试组织者
存根:
allow(SaveRecord).to receive(:call!) { :success }
allow(PushToService).to receive(:call!) { :success }
Run Code Online (Sandbox Code Playgroud)
去测试:
it { expect(interactor).to be_kind_of(Interactor::Organizer) }
it { expect(described_class.organized).to eq([SaveRecord, PushToService]) }
Run Code Online (Sandbox Code Playgroud)
call! method & organized variable
从交互器管理器源文件中找到,它试图在内部调用和使用。对call!
方法进行存根并测试organized
变量已满足我的要求。
归档时间: |
|
查看次数: |
1867 次 |
最近记录: |