我需要在一个参数上设定期望值。如何从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
要回答这个问题,请修改注释行。
感谢。
答案 0 :(得分:10)
刚想通了。 比我想象的要好得多。
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