How do I expect a message whose argument is any instance of a class in RSpec?

rspec, ruby, ruby-on-rails

Solution

`@controller.should_receive(:sign_in_and_redirect).with(an_instance_of(User))`

See the "Argument matchers" section of the Relish documentation for more details. I linked to the RSpec 2.13 docs, but there should be a select box that allows you to change the document version if you need to.

Update: In the RSpec 3.2 docs, they say to use `instance_of`.

Problem

How do I write a message expectation that expects to be called with any instance of a class? I'd like to do something like this: ``` @controller.should_receive(:sign_in_and_redirect).with(kind_of? User) ```

Original source