[MacRuby-devel] macruby rspec mock odd behavior
Joshua Ballanco
jballanc at gmail.com
Fri May 6 07:26:53 PDT 2011
Hi Gabriel,
So, you've stumbled across a bit of a confusing "feature" of MacRuby and interaction with Obj-C. The full method name of the Obj-C method, as Ruby sees it, is actually "buildRequestWithUrl:method:header:body:", since this is the selector. So, I think your mock should work if you simply modify it as follows:
@requestBuilder.should_receive(:"buildRequestWithUrl:method:header:body:")
.with("http://example.com", method: "POST", header: nil, body: anything() )
.and_return(nil)
Please let us know if that doesn't work!
Cheers,
Josh
On Wednesday, May 4, 2011 at 4:16 PM, Gabriel Ayuso wrote:
> Hi,
>
> I'm having some strange issue with rspec mocks and hope someone can point out what I'm doing wrong.
>
> I have a Objective C class with the method: buildRequestWithUrl:method:header:body:
> I wrote an rspec mock for this class. I'm setting up an expectation as follows:
>
> @requestBuilder.should_receive(:buildRequestWithUrl)
> .with("http://example.com", method:"POST", header:nil, body:anything() )
> .and_return(nil)
>
>
> When the class being tested calls the aforementioned method I get the following error:
>
> RuntimeError:
> NSInvalidArgumentException: -[Mock buildRequestWithUrl:method:header:body:]: unrecognized selector sent to instance 0x200373ea0
>
> I set the expectations for another method of the same class called :queryStringForDictionary
> In this case the expectation and call do work.
>
> @requestBuilder.should_receive(:queryStringForDictionary).and_return( body )
>
> In another project I'm calling the same class from ruby code and there the mocks and expectations do work properly. In this Objective C project they don't.
>
> Thanks in advance,
> Gabriel Ayuso
>
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
More information about the MacRuby-devel
mailing list