简体   繁体   English

命名路线打破了RSpec Michael Hartl的Ruby on Rails教程第5章

[英]Named routes break RSpec Michael Hartl's Ruby on Rails Tutorial Chapter 5

I am working through Michael Hartl's Ruby on Rails utorial. 我正在研究Michael Hartl的Ruby on Rails教程。 Everything works great until named routes are tested in Chapter 5, and they all break Rspec. 在第5章中测试命名路由之前,一切工作都很好,并且它们都破坏了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 但是,在我的Rspec文件中,以下内容会产生错误

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. 每个单独的命名路由都会失败,包括root_path,所以我的所有规格都失败了。

EDIT: 编辑:

Here is my routes.rb : 这是我的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'

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. 我认为该错误表明您忘记了在about块中包含访问about_path,这就是为什么它为您提供了未定义的变量或方法。 I think the answer is: 我认为答案是:

before { visit about_path }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM