[rspec-users] [TDD] [Rails] - Rspec test for application_helper.rb fails when trying to access application_controller method.

John Bruce jrbruce at gmail.com
Mon Nov 29 17:37:06 EST 2010

In a method named logo in my application helper, I reference an application controller method (current_account) that has been marked as a helper method with the following syntax: 

helper_method :current_account

When I test out the setup in the browser (without rspec), rails is happy with this setup.

However, when I run the spec, the spec won't pass and gives me the following error:

  1) ApplicationHelper#logo image tag should point to logo.png
     Failure/Error: helper.logo.should =~ /logo.png/i
     undefined local variable or method `current_account' for #<ActionView::Base:0x105645108>
     # ./app/helpers/application_helper.rb:13:in `logo'
     # ./spec/helpers/application_helper_spec.rb:21

Current Versions:
Rspec Version 2.1.0
Rails Version 3.0.1

I've created a gist that shows how my code is setup, and how the helper is calling the controller method:


Does anyone know why this setup works fine outside of rspec (when I test in the browser), but won't work within rspec?

Is there an object / instance variable that I need to mock, or a setting that I need to change in order for the helper spec to know about the controller methods that have been marked as helper methods?

John Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101129/fd832179/attachment.html>

More information about the rspec-users mailing list