ruby - rspec: 'should_receive' with multiple argument expectations -


i have function receives complex argument (an html string). want check multiple conditions string, i.e.:

receiver.should_receive(:post_data).with(json_content).with(id_matching(5)) 

multiple with arguments doesn't work, alternatives? i'm happy define custom matchers if it's possible make compound 1 in way.

obviously run same test multiple times , test different things result, integration test takes several seconds run, don't want make slower.

thanks

edit:

at time of writing, accepted answer (use custom matcher custom description), appears best option. isn't perfect, ideally with support concept of 'this item of expected type, wasn't 1 expected', instead of pure binary match.

you need provide custom matcher, can readily define error reporting can give specifics failed , why. see https://github.com/dchelimsky/rspec/wiki/custom-matchers , http://solnic.eu/2011/01/14/custom-rspec-2-matchers.html.

in particular, custom matcher supplied argument with, mentioned in last sentence of first paragraph of "argument matchers" section of https://github.com/rspec/rspec-mocks.

as error reporting, there no custom failure methods apply use case, description method of custom matcher used generate string shown "expected" value and, though not purpose, can defined output want regarding failed match.


Comments