在主方法上执行Rspec测试时如何模拟来自辅助方法调用的数据?

问题描述 投票:0回答:1

我正在尝试从方法[[helper中获取数组[1,2,3,4],该方法由名为basic ,应该使用返回的数组。在编写基本方法的测试时如何指定或硬编码该数组?

ruby-on-rails ruby rspec rspec-rails rspec2
1个回答
0
投票
模拟您的依赖项或消息呼叫

allow(self).to receive(:helper).with(params) or use (with_any) .and_return([1,2,3,4]).

在rspec2 @ https://relishapp.com/rspec/rspec-mocks/v/2-99/docs/method-stubs/allow-with-a-simple-return-value上查找更多信息>        
© www.soinside.com 2019 - 2024. All rights reserved.