title: Failure/Error: visit root_path NameError: undefined local variable or method `root_path'
body: <p>I am using rspec for testing my app, but I am having trouble using the visit method to access my root_path. I tried adding rails-controller-testing gem, but it came to no avail. Using Rails 5.1.1, Ruby 2.4.1, rspec 3.6.0.</p>
  
  <p>Here's my error:</p>
  
  <pre><code>$ rspec
  F
  
  Failures:
  
    1) navigate homepage can be reached successfully
       Failure/Error: visit root_path
  
   NameError:
     undefined local variable or method `root_path' for #&lt;RSpec::ExampleGroups::Navigate::Homepage:0x007fbf3c224748&gt;
   # ./spec/features/static_spec.rb:5:in `block (3 levels) in &lt;top (required)&gt;'
  
  Finished in 0.00378 seconds (files took 0.09639 seconds to load)
  1 example, 1 failure
  
  Failed examples:
  
  rspec ./spec/features/static_spec.rb:4 # navigate homepage can be reached successfully
  </code></pre>
  
  <p>The static_spec.rb file:</p>
  
  <pre><code>#spec/features/static_spec.rb
  require 'spec_helper'
  describe 'navigate' do
    describe 'homepage' do
      it 'can be reached successfully' do
        visit root_path
        expect(page.status_code).to eq(200)
      end
    end
  end
  </code></pre>
  
  <p>I already tried using this in spec_helper.rb</p>
  
  <pre><code>config.include rails.application.routes.url_helpers
  </code></pre>
  
  <p>Here is my route.</p>
  
  <pre><code>#config/routes.rb
  Rails.application.routes.draw do
  
    root :to =&gt; 'static#homepage'
  end
  </code></pre>
  
  <p>Here is rails_helper.rb</p>
  
  <pre><code>ENV['RAILS_ENV'] ||= 'test'
  require File.expand_path('../../config/environment', __FILE__)
  
  abort("The Rails environment is running in production mode!") if 
  Rails.env.production?
  require 'spec_helper'
  require 'rspec/rails'
  require 'capybara/rails'
  
  include Warden::Test::Helpers
  Warden.test_mode!
  
  ActiveRecord::Migration.maintain_test_schema!
  
  RSpec.configure do |config|
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = false
    config.before(:suite) { DatabaseCleaner.clean_with(:truncation) }
    config.before(:each) { DatabaseCleaner.strategy = :transaction }
    config.before(:each, :js =&gt; true) { DatabaseCleaner.strategy = :truncation }
    config.before(:each) { DatabaseCleaner.start }
    config.after(:each) { DatabaseCleaner.clean }
    config.infer_spec_type_from_file_location!
    config.filter_rails_from_backtrace!
    config.include FactoryGirl::Syntax::Methods
  end
  </code></pre>
  
  <p>How can I fix this error?</p>