【发布时间】:2016-04-06 00:17:51
【问题描述】:
我有一个这样调用的方法:
post_signup(user,
"fb signup completed",
app_context: current_app_id,
description: "Automatically Populated Via #{current_app_id}")
参数是值和关键字参数的混合。我在测试中关心的是app_context。我尝试了类似的方法,但它不起作用:
it "should log an event with an app_context" do
expect(controller).to receive(:post_signup).with(hash_including(app_context: current_app_id))
subject
end
和
it "should log an event with an app_context" do
expect(controller).to receive(:post_signup).with(current_app_id, any_args)
subject
end
男人能做什么?
【问题讨论】:
-
不要对好公民感到绝望,
hash_including的魔力仍然会拯救你! rubydoc.info/gems/rspec-mocks/RSpec/Mocks/… -
只是注意到您实际上尝试过... :D 但看起来您尝试将其作为第一个参数...但哈希是第二个参数,因此您需要类似:@987654326 @ 所以
anything匹配第一个参数(即user),然后将hash_include 用于它的其余部分(即哈希...) -
让这个答案@TarynEast