0

I'm writing a plugin that adds a method to controllers and declares it as a helper method. If it were done statically (rather than through the plugin), it would look something like this:

# in RAILS_ROOT/app/controllers/stuffed_animals_controller.rb
class StuffedAnimalsController < ActionController::Base

  private

  def bear
    'Teddy Bear'
  end

  helper_method :bear

end

# in RAILS_ROOT/app/views/stuffed_animals/index.html.erb:
<%= bear -%>

It works just fine. I want to test that :some_helper_method is actually a helper method, though. I tried this:

def test_declared_bear_as_helper_method
  assert StuffedAnimalsController.helper_methods.include?(:bear)
end

Unfortunately, ActionController::Base does not have a :helper_methods class method. Anyone know where I can get the list of things a class exposes via :helper_method?

4

1 回答 1

0

知道了!

def test_declared_bear_as_helper_method
  helper = Object.new
  helper.extend StuffedAnimalsController.master_helper_module
  assert helper.respond_to?(:bear)
end
于 2009-09-02T14:44:01.517 回答