Check Specific Arguments To Received Method
Let's say we have a method receiving a big hash of arguments. A hash like this:
In an RSpec test we want to check one of those hash values in a certain scenario. It can be tedious to type out and check the entire hash. Instead, we want the test to surgically check just one part of the hash.
We can do this with RSpec's dynamic matcher syntax. The hash_including
argument matcher can be nested within the #with
part of expect().to receive().with()
.
This will assert about the discounts
portion of the hash that #take_order
gets called with. The rest of the hash will be ignored.
Without hash_including
, the with
call would result in a failure when trying to match against the entire hash.
Last updated