[rspec-users] Class method not being stubbed

Nick Hoffman nick at deadorange.com
Sun May 24 16:49:52 EDT 2009

On Sun, May 24, 2009 at 3:25 PM, Rick DeNatale <rick.denatale at gmail.com> wrote:
>> However, that doesn't really matter. The call to #require shouldn't
>> happen, because the method is supposed to be stubbed out.
> No that's what confused me.
> class KeywordListsController < ApplicationController
> ...
>   private
> ...
>  def create_keywords_and_associate(keyword_list_contents, keyword_list)
>    puts '*** create_keywords_and_associate ***'
>    require 'lib/adsense_heaven_parser'
>    parsed_list = AdSenseHeavenParser.parse keyword_list_contents
> The controller method has the require and then calls parse.

Yup! But in my specs, when the controller method calls #parse , the
stub should consume the method call.

> One thing which strikes me is that if Rails naming conventions were
> being followed:
>  1) the file name be lib/ad_sense_heaven_parser not lib/adsense_heaven_parser

Normally, the file would be named like that. However, the class
represents a service called "AdSense Heaven", which doesn't have a
space between "Ad" and "Sense"...or should that still cause the file
to be named "ad_sense_..."?

>  2) the require wouldn't be needed since it would be autoloaded.

I thought that everything in lib/ should be autoloaded. When I found
that lib/adsense_heaven_parser.rb wasn't being autoloaded, I figured I
was wrong, and simply #require'd it in.

> Perhaps the problem lies there somewhere.

That's a good idea. I'll look into it and let you know.


More information about the rspec-users mailing list