我正在将 Rails 2.3.18 升级到 3.2.x,并且在这组 Controller 测试中遇到了问题:
错误:
/actionpack-3.2.12/lib/action_controller/test_case.rb:514:in `build_request_uri'
/actionpack-3.2.12/lib/action_controller/test_case.rb:470:in `process'
/actionpack-3.2.12/lib/action_controller/test_case.rb:49:in `process'
/actionpack-3.2.12/lib/action_controller/test_case.rb:390:in `get'
# ./spec/controllers/integrations/formstack_controller_spec.rb:104:in `block (3 levels) in <top (required)>'
代码触发错误:
it "should handle a failed access_token retreival" do
FormStack::Oauth2Connection.any_instance.stub(:identify).and_return(nil)
get "oauth_token" # this line <---------------------------------------------------------------- 104
response.should redirect_to(:controller => "/integrations/", :action => :index)
flash[:error].should include("error")
end
此 Controller 的路由:
namespace :integrations, path: "/integrations" do
match "formstack/oauth_token", :to => "formstack#oauth_token"
resources :formstack
end
我的 Controller 没有什么特别的:
class Integrations::FormstackController < ApplicationController
def oauth_token
...
end
end
那么它是关于什么的
get "any_action_in_this_controller"
导致这个relative_url_root错误?该 Controller 的每个操作的每次测试都会引发错误。
我还可以提供哪些其他信息来帮助你们帮助我调试这个问题?
最佳答案
正如 @marcario 所提到的,如果您有:
def config
end
在 Controller 中,您将收到此(模糊的)错误。只需将配置重命名为其他名称并匹配路由映射即可。
关于ruby-on-rails - 未定义方法relative_url_root为零:NilClass when running rspec on namespaced controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16444392/