title: Testing helper methods in Rails
body: <p>I'm testing my rails helper methods like this:</p>
  
  <pre><code>require File.dirname(__FILE__) + '/../../test_helper'
  require 'action_view/test_case'
  require 'action_view/helpers'
  
  class ListingsHelperTest &lt; ActionView::TestCase
  
    def setup
      @controller = ListingsController.new
      @request  = ActionController::TestRequest.new
      @response = ActionController::TestResponse.new
    end
  end
  </code></pre>
  
  <p>This works great, except where the helpers call on methods that require a request to have happened, such as <strong>url_for</strong>. Since I don't want to run the whole stack through a request process to test these (e.g. by calling get :index), what would need to be initialized or stubbed out for this to work?</p>
  
  <p>I'm looking for a more general solution to mock a request, but specifically, the error I'm getting is this:</p>
  
  <pre><code>NoMethodError: You have a nil object when you didn't expect it!
  The error occurred while evaluating nil.rewrite
  rails/actionpack/lib/action_controller/base.rb:625
  rails/actionpack/lib/action_view/helpers/url_helper.rb:85
  rails/actionpack/lib/action_view/helpers/url_helper.rb:85
  </code></pre>