[rspec-users] mock out render call in helper

Chris Hoffman bosshoff at gmail.com
Fri Apr 13 09:54:30 EDT 2007

I guess this question really boils down to the following:  what are
the proper means to access the object that is including the helper
being tested?  I have been reading through the documentation, and it
indicates that calling helper_name :foo will include FooHelper in the
context.  How then can I mock out methods in this object?

In case I am not being clear: say I have the following helper

module FooHelper
  def hello
     "hello world"

  def look_to_hello

I want to make sure the "look_to_hello" method calls "hello," without
"hello" actually being called.


On 4/13/07, Chris Hoffman <bosshoff at gmail.com> wrote:
> Okay, so if I use
> @controller.render :foo
> instead of just
> render :foo
> in the helper, I can mock it out fine in the specs with
> @controller.stub!(:render)
> Am I wrong to use the shortened "render :foo" form in the helpers, or
> is this a malfunction of RSpec?
> On 4/13/07, Chris Hoffman <bosshoff at gmail.com> wrote:
> > Hello,
> >   Does someone know where I can hook in to mock out a render call from
> > a helper in Rails?  I know I can do this in view specs with the
> > following
> >
> > @controller.template.stub!(:render)
> >
> > but template doesn't seem to be attached to @controller in a helper
> > context.  Thanks.
> >
> > -Chris
> >

More information about the rspec-users mailing list