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?
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
In your routes.rb, see if you have defined root
. Something like this:
root :to => 'home#index'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With