ruby-on-rails - 未定义方法relative_url_root为零:NilClass when running rspec on namespaced controller

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

我正在将 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/

相关文章:

ruby-on-rails - rails : render a collection of models using an specific html view

maven - 从多模块 Maven 项目构建单个 fat jar - 包括测试类

ruby-on-rails - rails 引擎 : Where to define gems only used in testing

ruby-on-rails - rails : Warden/Devise - How to capture the url before login/failed access

python - 数字代码回归测试框架

ruby-on-rails - 什么是好的代码测试比率?

ruby-on-rails - 如何测试优惠券/促销代码的唯一性?

ruby-on-rails - 如何从子记录集合中获取曾祖 parent 记录集合?

css - 我的网站打印不正确

ruby-on-rails - 外键 (class_id) 未填充在 belongs_to 关联中