我有一个用于许多功能(休息请求)的共享 rspec 示例。每个函数都会收到一个我要检查的哈希值,但它们可以位于不同的位置,例如:
get(url, payload, headers)
delete(url, headers)
我想编写以下测试:
shared_examples_for "any request" do
describe "sets user agent" do
it "defaults to some value" do
rest_client.should_receive(action).with(????)
run_request
end
it "to value passed to constructor"
end
end
end
describe "#create" do
let(:action) {:post}
let (:run_action) {rest_client.post(url, payload, hash_i_care_about)}
it_behaves_like "any request"
end
问题是,我怎样才能编写一个匹配任何参数的匹配器,例如:
client.should_receive(action).with(arguments_including(hash_including(:user_agent => "my_agent")))