[英]Controller test routing error with minitest-rails and rails 4.1
我使用minitest / minitest-rails获得以下“无路由匹配”错误:
1) Error:
SessionsController::#create#test_0002_get authenticated user session:
ActionController::UrlGenerationError: No route matches {:action=>"create", :controller=>"sessions"}
test/controllers/sessions_controller_test.rb:30:in `block (3 levels) in <top (required)>'
但其他人得到:新的和获得:破坏路线是好的。 这是test / controllers / sessions_controller_test.rb
require "test_helper"
describe SessionsController do
describe "#new" do
it "GET, /signin" do
get :new
assert_response 302
end
it "GET, /auth/github" do
get :new
assert_redirected_to '/auth/github'
end
end
describe "#create" do
specify { request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:github] }
it "get authenticated user session" do
--> get :create
...
end
end
describe "#destroy" do
it "GET, /signout and reset_session" do
get :destroy
session[:user_id].must_equal nil
end
it "GET, / by redirect_to root_url" do
get :destroy
assert_response 302
assert_redirected_to root_path
end
end
end
这是控制器:
class SessionsController < ApplicationController
def new
redirect_to '/auth/github'
end
def create
auth = request.env["omniauth.auth"]
user = User.where(:token => auth['credentials']['token']).first ||
User.create_with_omniauth(auth)
reset_session
session[:user_id] = user.id.to_s
end
def destroy
reset_session
redirect_to root_url, :notice => 'Signed out!'
end
end
路线:
$ rake routes|grep session
auth_github_callback GET /auth/:provider/callback(.:format) sessions#create
signin GET /signin(.:format) sessions#new
signout GET /signout(.:format) sessions#destroy
$ grep session config/routes.rb:
get '/auth/:provider/callback' => 'sessions#create', :as => :auth_github_callback
get '/signin' => 'sessions#new', :as => :signin
get '/signout' => 'sessions#destroy', :as => :signout
从Gemfile.lock中提取minitest相关性:
minitest (~> 5.1)
minitest (5.3.3)
minitest-capybara (0.6.1)
minitest (~> 5.0)
minitest-metadata (0.5.0)
minitest (>= 4.7, < 6.0)
minitest-rails (2.0.1)
minitest (>= 5.3.3, < 6.0)
minitest-rails-capybara (2.0.0)
minitest-capybara (~> 0.6.1)
minitest-metadata (~> 0.5.0)
minitest-rails (~> 2.0.0)
minitest-rails-capybara
该应用程序在Rails 4.1.0 / ruby 2.1.1p76上运行。
该应用程序在开发中运行良好,这让我觉得测试路由出了问题,有些路由很好,只是创建失败。
到现在为止,我不知道在哪里看。
路线期待:provider
在场。 您没有指定该值,因此路由器无法将请求与控制器操作相匹配。 尝试将测试更改为以下内容:
get :create, provider: "github"
如果您在未提供:id
值的情况下调用show
动作,则会出现同样的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.