我需要对一个参数设置期望值。如何访问从 RSpec 接收到的参数?
这是我想要实现的。
let(:api) { double('API') }
it "should pass :filter in options" do
api.should_receive(:traverse)
subject.execute
args = api.recevied_arguments_for(:traverse) # How to obtain all the arguments?
args[0].should have_key(:filter)
end
要回答问题,请用评论修复该行。
谢谢。
最佳答案
刚刚想通了。 比我想象的要好得多。
let(:api) { double('API') }
it "should pass :filter in options" do
api.should_receive(:traverse).with hash_including(:filter)
# or with the exact value
#api.should_receive(:traverse).with hash_including(:filter => 'something')
subject.execute
end
关于ruby-on-rails - 使用 RSpec 验证部分参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8393198/