使用 rspec-expectations 3.13.3 并具有如下代码:
def methname(**kwargs)
# let's assume this method doesn't mind whether the kwargs are keyed by symbols or strings
p(received: kwargs)
end
使用如下测试
expect(something).to receive(:methname).with(hash_including(what_ever: "else"))
但在某些情况下,关键字参数被创建为字符串,而不是符号,因此失败了,我必须这样做
expect(something).to receive(:methname).with(hash_including("what_ever" => "else"))
我可以在每个规范中做到这一点,但如果我可以无差别地匹配它,对我来说会更干净 -
# desired code
expect(something).to receive(:methname).with(hash_including_indifferently(what_ever: "else"))
有没有办法可以做到这一点?