【发布时间】:2016-07-03 16:50:49
【问题描述】:
所以我正在关注 Michael Hartl 的 Rails 教程,我正在学习第 5 章 (https://www.railstutorial.org/book/filling_in_the_layout)。
当我运行他为注册链接添加的最终测试时:
class UsersControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get signup_path
assert_response :success
end
end
我在运行测试时收到此错误:
ERROR["test_should_get_new", UsersControllerTest, 2016-07-01 17:48:25 +0100]
test_should_get_new#UsersControllerTest (1467391705.83s)
ActionController::UrlGenerationError: ActionController::UrlGenerationError: No route matches {:action=>"/signup", :controller=>"users"}
test/controllers/users_controller_test.rb:6:in `block in <class:UsersControllerTest>'
test/controllers/users_controller_test.rb:6:in `block in <class:UsersControllerTest>'
这里是路由文件:
Rails.application.routes.draw do
root 'static_pages#home'
get '/signup', to: 'users#new'
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
end
我在视图中使用了 signup_path 助手作为链接,它们工作正常。
当我在路由中定义“signup”应该成为用户控制器中的新操作时,为什么 test 会尝试访问名为“/signup”的操作?
【问题讨论】:
标签: ruby-on-rails testing path get routes