Mocking Class Methods

20 views
Skip to first unread message

Mark Meyer

unread,
Nov 24, 2014, 4:09:01 PM11/24/14
to cedar-...@googlegroups.com
Is it possible to mock class methods while using Cedar? 

I couldn't find any examples in the wiki

Andrew Kitchen

unread,
Nov 24, 2014, 5:40:11 PM11/24/14
to cedar-...@googlegroups.com
Hi Mark, 

Do you mean to say that you would like to stub class methods?

This is possible as far as I recall, though generally not recommended for reasons that are not Cedar-specific.

here's an example of what it would look like:

    describe(@"spying on a class", ^{

        it(@"is supported", ^{

            id junk = [[NSObject alloc] init];

            spy_on([UIApplication class]);


            [UIApplication class] stub_method(@selector(sharedApplication)).and_return(junk);


            [UIApplication sharedApplication] should be_same_instance_as(junk);

        });

    });


On Mon, Nov 24, 2014 at 1:09 PM, Mark Meyer <mme...@sharethrough.com> wrote:
Is it possible to mock class methods while using Cedar? 

I couldn't find any examples in the wiki

--
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.

Reply all
Reply to author
Forward
0 new messages