ApplicationHelper is not loaded in helper specs #276

Closed
livedo opened this Issue Nov 30, 2010 · 6 comments

Projects

None yet

3 participants

@livedo
livedo commented Nov 30, 2010

With rails 3.0.3, rspec/rspec-rails 2.2.0.

It seems that ApplicationHelper is not loaded in helper specs.

Consider the following ApplicationHelper

module ApplicationHelper
  def test_helper_method
    "works"
  end
end

and a helper method which calls another helper method defined in the ApplicationHelper

module TestingHelper
  def generic_helper_caller
    test_helper_method
  end
end

Now this test

describe TestingHelper do
  describe "with loading ApplicationHelper" do
    it "should see methods from ApplicationHelper" do
      helper.generic_helper_caller.should == "works"
    end
  end
end

will fail like so

1) TestingHelper with loading ApplicationHelper should see methods from ApplicationHelper
 Failure/Error: helper.generic_helper_caller.should == "works"
 undefined local variable or method `test_helper_method' for #<ActionView::Base:0x103506898>
 # ./app/helpers/testing_helper.rb:4:in `generic_helper_caller'
 # ./spec/helpers/testing_helper_spec.rb:16
@livedo
livedo commented Dec 1, 2010

Had a bug in the test, and the wrong failure at first, but now they are right and the problem still persists.

@dchelimsky
Member

For now you can do this:

helper.extend(ApplicationHelper)

Seems like that would be a reasonable default. On the flip-side, there is no unextend, so anybody who does not want ApplicationHelper included would be pretty well screwed. Question is whether that's even valid, since Rails will include ApplicationHelper for you anyway.

WDYT?

@livedo
livedo commented Dec 1, 2010

Well. I think that Rails 3 has gone all upside down with helper visibility.
In 2.x, it used to be that if you declare nothing in ApplicationController, you get ApplicationHelper and the helper by controller name convention, and you had to say
helper :all
to make all helpers show everywhere.

However in Rails 3, helper :all is taken as default, and you need to say
clear_helpers
in ApplicationController to get the functionality of the previous convention.

See https://rails.lighthouseapp.com/projects/8994/tickets/3945 and https://rails.lighthouseapp.com/projects/8994/tickets/4750

So. I think that ApplicationHelper should always be loaded in helper specs.

@dchelimsky
Member

Include ApplicationHelper in helper object in helper specs.

@TiagoCardoso1983

Hi,

I don't know if this has been taken into account, but sometimes one defines a function in a certain controller helper that overwrites a function in ApplicationHelper. In such cases, the late inclusion of the ApplicationHelper as it is currently being done breaks the specs.

@dchelimsky
Member

@TiagoCardoso1983 if you are experiencing a problem then please submit a new issue. Thanks.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment