[rspec-users] spec'ing helpers that use controller

Courtenay court3nay at gmail.com
Tue Jul 24 19:30:03 EDT 2007


On 7/24/07, Rick Tessner <rick.tessner at gmail.com> wrote:
> Hi,
>
> On Tue, 2007-24-07 at 15:26 -0700, Courtenay wrote:
> > Does this work?
> >
> >   ApplicationHelper.stub!(:controller).and_return mock('controller',
> > :controller_name => 'foo')
>
> Sadly, no.  Same result:
>
>         undefined local variable or method `controller' for [RSpec
>         example]: #<Class:0xb7149760>

specing helpers just includes the module in your spec.

So you can cheat like

describe "Application Helper" do
  helper_name :application

  def controller
    @controller
  end

  before(:each) do
    @controller = mock('controller')
  end

  it "should blah blah" do
  end

end


More information about the rspec-users mailing list