0

更新到 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 似乎有相当多的相关问题 - 所有问题都未解决或没有具体解决方案。

任何人都知道如何解决这个问题?

4

1 回答 1

0

rails-translate-routes README ( https://github.com/francesc/rails-translate-routes#testing )的“测试”部分解释了必须将语言环境作为参数添加到操作调用中。

get :new

必须改为这样的东西:

get :new, locale: 'en'

如自述文件中所述,存在一个猴子补丁以避免这样做的必要性。

一个问题仍然存在:为什么在 Rails 3.2.6/Journey 1.0.3 中没有添加它也能工作?

于 2013-02-02T15:31:18.590 回答