undefined方法relative_url_root for nil:在命名空间控制器上运行rspec时的NilClass

时间:2013-05-08 15:20:07

标签: ruby-on-rails ruby-on-rails-3 testing rspec rspec2

我正在进行2.3.18到3.2.x的升级,我遇到了一组控制器测试的问题:

错误:

/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

此控制器的路线:

namespace :integrations, path: "/integrations" do
    match "formstack/oauth_token", :to => "formstack#oauth_token"
    resources :formstack
end

我的控制器没什么特别的:

class Integrations::FormstackController < ApplicationController
    def oauth_token
       ...
    end
end

那是什么呢?

get "any_action_in_this_controller"

导致这个relative_url_root错误?对于此控制器的每个操作的每个测试都会引发错误。

我可以提供哪些其他信息,这有助于你们帮我调试一下?

1 个答案:

答案 0 :(得分:4)

如@marcario所述,如果你有:

    def config
    end

在控制器中,您将收到此(模糊)错误。只需将配置重命名为其他内容并将路线映射匹配即可。