Ruby on rails 4 ActionController::RoutingError:没有与[DELETE]匹配的路由/注销“;
我目前正在学习MichaelHartl的RoR教程和第8章:登录,注销>清单8.28 test/integration/users\u login\u test.rbRuby on rails 4 ActionController::RoutingError:没有与[DELETE]匹配的路由/注销“;,ruby-on-rails-4,Ruby On Rails 4,我目前正在学习MichaelHartl的RoR教程和第8章:登录,注销>清单8.28 test/integration/users\u login\u test.rb require 'test_helper' class UsersLoginTest < ActionDispatch::IntegrationTest def setup @user = users(:aniket) end test "login with valid information"
require 'test_helper'
class UsersLoginTest < ActionDispatch::IntegrationTest
def setup
@user = users(:aniket)
end
test "login with valid information" do
get login_path
post login_path, session: { email: @user.email, password: 'password' }
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end
test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, session: { email: "", password: "" }
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end
test "login with valid information followed by logout" do
get login_path
post login_path, session: { email: @user.email, password: 'password' }
assert is_logged_in?
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
delete logout_path
assert_not is_logged_in?
assert_redirected_to root_url
follow_redirect!
assert_select "a[href=?]", login_path
assert_select "a[href=?]", logout_path, count: 0
assert_select "a[href=?]", user_path(@user), count: 0
end
end
需要“测试助手”
类UsersLoginTest
按照指示,我正在执行用户注销测试。我已经阅读了我的代码,它与书中提到的完全一样。但是,当我运行测试套件时,我得到以下错误
1)错误:
UsersLoginTest#test(测试)登录(带有有效信息)(后跟(注销):
ActionController::RoutingError:没有与之匹配的路由[DELETE]“/logout”
test/integration/users\u login\u test.rb:40:in'block in'
21次运行,53次断言,0次失败,1次错误,0次跳过
我似乎不明白我哪里出错了。请帮助您的
路线是什么
?错误就是告诉你到底出了什么问题。您没有DELETE”/logout“
路径。发布你的config/routes.rb
文件中声明route.Rails.application.routes.draw do-get'sessions/new'get'users/new'root'static\u pages#home'get'help'=>'static\u pages#help'get'about'=>'static\u pages#about'get'contact'=>'static\u pages“用户”#新建“获取”登录“=>”会话#新建“发布”登录“=>”会话#创建“获取”注销“=>”会话#销毁”资源:用户端获取“注销”
与删除“注销”
不同。您的测试需要删除“注销”
。谢谢,伙计!成功了!不,您发布的链接清楚地显示了删除“注销”=>“会话”#销毁”
。