0

I am working through Michael Hartl's Ruby on Rails utorial. Everything works great until named routes are tested in Chapter 5, and they all break Rspec. I have confirmed that they all work correctly in the browser, and in views.

For example, in a layout the following works:

<li><%= link_to "About", about_path %></li>

However, in my Rspec file the following produces an error

visit about_path

The error I'm getting is:

Failure/Error: visit about_path 
 NameError:
undefined local variable or method 'about_path' for #<Rspec::Core::ExampleGroup.....

Every single named route fails including root_path, so all of my specs fail.

EDIT:

Here is my routes.rb:

root to: 'static_pages#home'
match '/help', to:'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
user4815162342
  • 141,790
  • 18
  • 296
  • 355
John Moore
  • 109
  • 2
  • 7
  • can we see your routes.rb? – Huy Mar 18 '13 at 18:03
  • Sure - here's the section of my routes file. It works when navigating through the browser: `root to: 'static_pages#home'` `match '/help', to:'static_pages#help'` `match '/about', to: 'static_pages#about'` `match '/contact', to: 'static_pages#contact'` – John Moore Mar 19 '13 at 18:59
  • Sorry, I can't seem to get the formatting right. Each of these is on a new line. – John Moore Mar 19 '13 at 19:02
  • You should also include the relevant part of your RSpec file so we can see exactly where and how you used `visit about path`. Thanks. – aceofbassgreg Mar 20 '13 at 14:00
  • 1
    Are you using spork? Try restarting the spork server. http://stackoverflow.com/questions/19101618/rspec-not-finding-my-named-routes – John Ong Oct 19 '13 at 01:49

1 Answers1

0

I think the error suggests that you have forgotten to include visit about_path in a before block that's why it's giving you an undefined variable or method. I think the answer is:

before { visit about_path }
PericlesTheo
  • 2,429
  • 2
  • 19
  • 31