路由在 RSpec 集成测试中不可用
我正在按照 Rails 教程网站 中的示例进行操作,但在使集成测试正常工作时遇到问题。特别是教程中第 8.4.2 节中清单 8.20 的示例。
在下面的访问signup_path行代码中,我收到以下错误:“未定义的局部变量或方法`signup_path'”
require 'spec_helper'
describe "Users" do
describe "signup" do
describe "failure" do
it "should not make a new user" do
visit signup_path
fill_in "Name", :with => ""
fill_in "Email", :with => ""
fill_in "Password", :with => ""
fill_in "Confirmation", :with => ""
click_button
response.should render_template("users/new")
response.should have_selector("div#error_explanation")
end
end
end
end
但是,如果我一次运行所有测试,则不会收到错误。< /strong> 仅当我运行该单独测试时才会发生该错误。
我的项目可以在 github 上查看此处
如何修复此错误?
I am following the examples in the Rails Tutorial website and I'm having issues getting the integration tests to work. Specifically the example at listing 8.20 in section 8.4.2 in the tutorial.
At the visit signup_path line of code below I get the following error: "undefined local variable or method `signup_path'"
require 'spec_helper'
describe "Users" do
describe "signup" do
describe "failure" do
it "should not make a new user" do
visit signup_path
fill_in "Name", :with => ""
fill_in "Email", :with => ""
fill_in "Password", :with => ""
fill_in "Confirmation", :with => ""
click_button
response.should render_template("users/new")
response.should have_selector("div#error_explanation")
end
end
end
end
Here's the full test file on github
However, if I run all the tests at once, then I do not get the error. The error only happens when I run that individual test.
My project can be viewed on github here
How do I fix this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一番努力,我意识到这根本不是一个 ID(至少在 Rails 3.0.3 中),而是一个名为 id_error_explanation 的类。
修复了将最后一位替换为:
response.should have_selector('div.id_error_explanation')
。After a bit of a struggle I've realized this isn't an ID at all (at least in Rails 3.0.3), rather a class, named
id_error_explanation
.Fixed with replacing the last bit with:
response.should have_selector('div.id_error_explanation')
.您应该根据清单 8.21 更改测试。测试将如下所示:
spec/requests/users_spec.rb:
You are supposed to change the test according to listing 8.21. The test would then look like this:
spec/requests/users_spec.rb: