Rafa de Castro Rafa de Castro - 2 months ago 16
Ruby Question

Checking parameters of method calls to a test double in RSpec

Is it possible to check if the parameters passed to the parameters of a method call fulfill certain constraints. I would like to do something like

my_double = double("MyObject")
my_double.should_receive(:mocked_method).with{ <something that has an attribute called name and value "john"> }

Thanks a lot in advance.

Edit: I'll try to clarify a bit what I want to accomplish

What I want is to check that a given method of a mock was called passing an object that fulfils some conditions


For the record. What I wanted to accomplish can be made with

  @test_double.should_receive(:send_mail) do |mail|
    mail.to.should eq(["john@aol.com"])
    mail.body.decoded.should include "Error"

And the code should call the method send_mail of the given object with a parameter that fulfills the conditions specified in the block.