这是我写成project_test.rb的单元测试
require 'test_helper'
class ProjectTest < ActiveSupport::TestCase
test "projects" do
visit new_project_path
click_link "new_Project"
fill_in "Title", :with => "test app"
fill_in "Project_type", :with => "basic"
fill_date "Date_fielded" , :with => "2012/12/3"
fill_in "Owner name", :with => "chetan"
fill_in "Status", :with => "new"
fill_in "Brand", :with => "nike"
click_link "Create_Project"
end
end
我得到这个作为错误
1) Error:
test_projects(ProjectTest):
NameError: undefined local variable or method `new_projects_path' for #<ProjectTest:0xaa6a25c>
test/unit/project_test.rb:5:in `block in <class:ProjectTest>'
我尝试更改路径以检查路径中的错误,但这不起作用 并且还检查了耙子路线以检查路径
这应该是new_project_path
的,即 project
应该是单数而不是复数。有关详细信息,请参阅路径和 URL 上的 Rails 路由文档部分。
看到转储会很有用
rake routes
但我怀疑链接名称是错误的,应该是
new_project_path
而不是
new_projects_path
此外,如果您使用的是 RESTful 路由,那么您很可能在new_project_path页面上没有 new_Project 链接,它更有可能在索引 (projects_path) 上,但 rake 路由将有助于缩小范围。
您需要从ActionDispatch::IntegrationTest
进行子类来编写集成测试(ActionController::TestCase
用于控制器功能测试)。
ActionDispatch::IntegrationTest
为您设置了 URL 帮助程序等内容。