Read more

You can use any RSpec matcher to match arguments of method calls

Henning Koch
October 17, 2011Software engineer at makandra GmbH

RSpec lets you define the arguments with which you expect a method to be invoked:

subject.should_receive(:say).with('hello')
Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

Sometimes you don't care about the exact arguments. For such cases RSpec comes with argument constraints Show archive.org snapshot like anything or hash_including:

subject.should_receive(:update_attributes).with(hash_including(:message => 'hi world'))

You can go even further and use any RSpec matcher to match arguments:

subject.should_receive(:say).with(instance_of(String))
Posted by Henning Koch to makandra dev (2011-10-17 16:01)