Getting the object passed as an argument to the flashed method using 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 

Basically, I want to examine the object passed as an argument for the cropped method to check the value of this object. In my situation, I cannot use Foo.expects(:bar).with({:abc => 123}) because I know that the object will not be equal to each other. I just want to compare the auxiliary value of the argument.

Of course, this is possible, I just cannot find the syntax or strategy here.

+6
ruby mocking mocha stubbing
source share
1 answer

I get it! Turns off with can take a block.

 Foo.expects(:bar).with do |the_hash| the_hash[:abc] == 123 end 
+11
source share

All Articles