[rspec-users] Class method not being stubbed

Nick Hoffman nick at deadorange.com
Sun May 24 13:47:53 EDT 2009


On Sun, May 24, 2009 at 1:10 PM, Rick DeNatale <rick.denatale at gmail.com> wrote:
> On Sun, May 24, 2009 at 12:25 PM, Nick Hoffman <nick at deadorange.com> wrote:
>> Hi guys. I'm setting an expectation on a class method. For some
>> reason, the method isn't being stubbed, and the expectation isn't
>> seeing the call.
>>
>> In KeywordListsController#create, I call the private method
>> #create_keywords_and_associate, which calls AdSenseHeavenParser#parse
>> .
>>
>> Thus, some of my specs set an expectation on AdSenseHeavenParser#parse
>> . However, that expectation isn't stubbing out #parse .
>
> That's because it isn't a class method, it's an instance method, so instead of:
>
> AdSenseHeavenParser.should_receive(:parse).with(keyword_list_contents).and_return({:keywords
> => [], :errors => []})
>
> You should have
> controller.should_receive(:parse).with(keyword_list_contents).and_return({:keywords
> => [], :errors => []})
>
> --
> Rick DeNatale

Hi Rick. I'm not sure what gave you the impression that #parse is an
instance method, but it definitely isn't.

#parse is a class method inside the AdSenseHeavenParser class.
KeywordListsController doesn't have a #parse method:
    http://pastie.org/488252

-Nick


More information about the rspec-users mailing list