[rspec-users] mock out render call in helper

Chris Hoffman bosshoff at gmail.com
Fri Apr 13 10:03:25 EDT 2007


Sorry for this stream of consciousness.  I am trying to work through a
problem, and without the benefit of being able to discuss these
situations with my colleague (who is not with the department any
longer), I find it necessary to reason through my conundrums by
writing.

Anyway, I think I have discovered the proper means to achieve what I
was talking about in previous posts.  'self' in the spec seems to give
one access to the object that is including the helper being spec'd.

-Chris

On 4/13/07, Chris Hoffman <bosshoff at gmail.com> wrote:
> 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"
>   end
>
>   def look_to_hello
>       hello
>   end
> end
>
> I want to make sure the "look_to_hello" method calls "hello," without
> "hello" actually being called.
>
> Thanks.
>
> 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