更新到 Rails 3.2.6 或 Rspec 2.11.0 时的 SO-thread Routing 错误很好地解释了这个问题:
旅程 >= 1.0.4 (Rails 3.2.11) ,所有与路由相关的单元测试都失败,而应用程序本身继续正常运行。
使用Rails 3.2.6并将旅程锁定到 1.0.3 是一种已变得不可接受的解决方法。
例如,这是最简单的失败测试之一:
路线.rb
ProjRails::Application.routes.draw do
devise_for :users, :controllers => {:registrations => "users/registrations"}
resources :users do
collection do
get 'current' => 'users#redirect', :as => :current
end
end
# ...
end
end
users_controller_test.rb
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
setup do
@user = FactoryGirl.create(:user)
@current_user = FactoryGirl.create(:user)
sign_in @current_user
end
# ...
test "should get new" do
get :new # this is line 25
assert_response :success
end
# ...
end
堆栈跟踪
8) Error:
test_should_get_new(UsersControllerTest):
ActionController::RoutingError: No route matches {:controller=>"users", :action=>"new"}
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:533:in `raise_routing_error'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:529:in `rescue in generate'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:521:in `generate'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:562:in `generate'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:558:in `generate_extras'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:554:in `extra_keys'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_controller/test_case.rb:151:in `assign_parameters'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_controller/test_case.rb:463:in `process'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_controller/test_case.rb:49:in `process'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.2/lib/devise/test_helpers.rb:19:in `block in process'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.2/lib/devise/test_helpers.rb:71:in `catch'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.2/lib/devise/test_helpers.rb:71:in `_catch_warden'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.2/lib/devise/test_helpers.rb:19:in `process'
/home/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.11/lib/action_controller/test_case.rb:390:in `get'
/home/me/proj/test/functional/users_controller_test.rb:25:in `block in <class:UsersControllerTest>'
关于 SO 似乎有相当多的相关问题 - 所有问题都未解决或没有具体解决方案。
任何人都知道如何解决这个问题?