Stub class method

164 views
Skip to first unread message

jby...@kineticcafe.com

unread,
Mar 8, 2015, 4:06:37 PM3/8/15
to cedar-...@googlegroups.com
Hi,

I was wondering if Cedar provides class method stubbing out of the box like OCMock. If it is, could you provide an example/guide on how to do it? 

Thanks

JB

Andrew Kitchen

unread,
Mar 8, 2015, 4:09:41 PM3/8/15
to cedar-...@googlegroups.com
Yes, it does. The API is identical - simply spy_on the Class first.



--
You received this message because you are subscribed to the Google Groups "Cedar Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cedar-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jby...@kineticcafe.com

unread,
Mar 20, 2015, 10:48:20 AM3/20/15
to cedar-...@googlegroups.com
Oh cool. Thanks Andrew.

catraniu...@gmail.com

unread,
Nov 24, 2015, 10:54:07 AM11/24/15
to Cedar Discussion, jby...@kineticcafe.com
Guys, could you help me out?

I'm trying to stub a class method of NSDate but it doesn't seem to work.

spy_on([NSDate class]);

NSDate *fakeDate = fake_for([NSDate class]);

fakeDate stub_method(@selector(date)).and_return(fakeDateToReturn);


When I do the above I get error: Attempting to stub method <date>, which double <Fake implementation of NSDate class> does not respond to
(null)

Cheers,
Serghei

Andrew Kitchen

unread,
Nov 24, 2015, 10:56:40 AM11/24/15
to cedar-...@googlegroups.com, Cedar Discussion, jby...@kineticcafe.com
It looks like a coding mistake - after spying on the class your code then creates a fake instance. Remove the second line and fix the third to refer to the class, and it should work.

catraniu...@gmail.com

unread,
Nov 24, 2015, 9:50:59 PM11/24/15
to Cedar Discussion, jby...@kineticcafe.com
Thanks for the reply! It worked. 

For posterity here's the code that works:

spy_on([NSDate class]);

[NSDate class] stub_method(@selector(date)).and_return(fakeDateToReturn);

Reply all
Reply to author
Forward
0 new messages