开发者

getting the object passed as an argument to a stubbed method with Mocha

开发者 https://www.devze.com 2023-02-13 01:56 出处:网络
Foo.expects(:bar) Foo.bar(:abc => 123, :xyz => 987) # assert Foo.bar was cal开发者_StackOverflowled with a hash that has a key of :abc == 123
Foo.expects(:bar)
Foo.bar(:abc => 123, :xyz => 987)

# assert Foo.bar was cal开发者_StackOverflowled 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.


I figured it out! Turns out with can take a block.

Foo.expects(:bar).with do |the_hash|
  the_hash[:abc] == 123
end
0

精彩评论

暂无评论...
验证码 换一张
取 消