[rspec-users] mock out render call in helper

Ashley Moran work at ashleymoran.me.uk
Fri Apr 13 11:29:32 EDT 2007


On 13 Apr 2007, at 14:54, Chris Hoffman wrote:

> module FooHelper
>   def hello
>      "hello world"
>   end
>
>   def look_to_hello
>       hello
>   end
> end

Chris,

The approach I've taken is to turn the support methods into methods   
on separate objects, eg (not that I've had this exact problem)

module FooHelper
   class Greeter
     def hello
       "hello world"
     end
   end

   def look_to_hello
     Greeter.new.hello
   end
end

You could make it "hello" class method if you're not bothered about  
blanket stubbing.  (I tend to go with objects just in case I want to  
inject them later, rather than have them created in-place with new)

Ashley




More information about the rspec-users mailing list