Forum: Ruby on Rails How to test with RSpec a Rails plugin using “link_to” and “current_page?”

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Christian L. (Guest)
on 2008-10-12 17:29
(Received via mailing list)
I'm writing a Rails plugin that builds up a menu in a view. I'm using
*link`_`to* to build the link and *current_page?* to set
class="active" on the current page.

I've *include*d *ActionView::Helpers::UrlHelper* so I can use

To get *current`_`page?* working in the view, I've had to inherit the
current class (apparently ActionView::Base) and it works perfectly
well. Unfortunately, this totally breaks the tests with RSpec.

I'm calling *link`_`to* and *current`_`page?* like this:

    def menu(options = {}, &block)
      carte =
      yield carte
      carte.to_s unless carte.empty?

    class my_menu
      include ActionView::Helpers::TagHelper
      include ActionView::Helpers::UrlHelper

      def initialize(base)
        @base = base

      def link
        @base.link_to(name, url_options, html_options)

And I get this error with RSpec:
    Undefined method `link_to' for #<

Any clue?
This topic is locked and can not be replied to.