undefined local variable or method `root_path'
rspec, ruby-on-rails, ruby-on-rails-4
Solution
Named routes are not available in specs by default. Add the following code to `spec_helper.rb`:
RSpec.configure do |config|
config.include Rails.application.routes.url_helpers
end
Problem
I have the following block of code in my rspec file located in the root of the /spec folder. ``` require 'spec_helper' describe "home" do subject { page } before(:each) { visit root_path } describe "page" do it { should have_title('My Page')} end end ``` When I run it I get ``` undefined local variable or method `root_path' ``` Which doesn't make any sense. When I followed the rails tutorial a similar set up worked just fine. Can anyone help? EDIT: My routes includes ``` root "static#home" ``` EDIT 2: Reopening this topic. Moving my root declaration to the top did not fix it. EDIT 3: What worked was including url_helpers in my rspec config. I've never had to do this before. can anyone answer why this worked?