rspec: 'should_receive' with multiple argument expectations
integration-testing, rspec, ruby, testing
Solution
You need to provide a custom matcher, but you can readily define your error reporting so that you can give specifics about what failed and why. See https://github.com/dchelimsky/rspec/wiki/Custom-Matchers .
In particular, the custom matcher would be supplied as the argument to `with`, as mentioned in the last sentence of the first paragraph of the "Argument Matchers" section of https://github.com/rspec/rspec-mocks.
As for error reporting, there are no custom failure methods that apply to this use case, but the `description` method of the custom matcher is used generate the string shown as the "expected" value and, though not its purpose, can be defined to output anything you want regarding the failed match.
Problem
I have a function which receives a complex argument (an HTML string). I want to check multiple conditions about this string, i.e.: ``` receiver.should_receive(:post_data).with(json_content).with(id_matching(5)) ``` Multiple `with` arguments doesn't work, any alternatives? I'm happy to define custom matchers if it's possible to make a compound one in some way. Obviously I could run the same test multiple times and test different things about the result, however this is an integration test which takes several seconds to run, so I don't want to make it even slower. Thanks EDIT: At time of writing, the accepted answer (use a custom matcher with custom description), appears to be the best option. However it isn't perfect, ideally `with` would support a concept of 'this was an item of the expected type, but wasn't the one we expected', instead of a pure binary match.