使用 Mocha 将对象作为参数传递给存根方法
Foo.expects(:bar)
Foo.bar(:abc => 123, :xyz => 987)
# assert Foo.bar was called with a hash that has a key of :abc == 123
基本上我想检查作为参数传递给存根方法的对象,以便检查该对象的值。在我的情况下,我不能使用 Foo.expects(:bar).with({:abc => 123}) 因为我知道对象不会彼此相等。我只想比较参数的子值。
当然这是可能的,我只是在这里找不到语法或策略。
Foo.expects(:bar)
Foo.bar(:abc => 123, :xyz => 987)
# assert Foo.bar was called with a hash that has a key of :abc == 123
Basically I want to examine the object passed as an argument to a stubbed method, in order to inspect on a value of that object. In my situation I can't use Foo.expects(:bar).with({:abc => 123})
because I know the object wont equal each other. I just want to compare a sub-value of the argument.
Surely this is possible, I just can't find the syntax or strategy here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了!事实证明
with
可以占用一个块。I figured it out! Turns out
with
can take a block.