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

时间:2022-06-03 00:15:22

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.

我正在研究Michael Hartl的Ruby on Rails utorial。一切都很有效,直到命名路线在第5章中进行测试,它们都会打破Rspec。我已经确认它们在浏览器和视图中都能正常工作。

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'

1 个解决方案

#1


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:

我认为错误表明你忘记在前一个块中包含访问about_path,这就是为什么它给你一个未定义的变量或方法。我认为答案是:

before { visit about_path }

#1


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:

我认为错误表明你忘记在前一个块中包含访问about_path,这就是为什么它给你一个未定义的变量或方法。我认为答案是:

before { visit about_path }