Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails路径帮助程序在rspec功能测试中不接受资源参数_Ruby On Rails_Rspec - Fatal编程技术网

Ruby on rails Rails路径帮助程序在rspec功能测试中不接受资源参数

Ruby on rails Rails路径帮助程序在rspec功能测试中不接受资源参数,ruby-on-rails,rspec,Ruby On Rails,Rspec,我开始将我的RSpec请求规范移动到功能中,以符合新模式 但是,当我访问spec/features示例中的路径帮助器时,如下所示: visit orgs_path(reader.org) 我得到这个错误: Failure/Error: visit org_path(reader.org) ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"orgs",

我开始将我的RSpec
请求
规范移动到
功能
中,以符合新模式

但是,当我访问
spec/features
示例中的路径帮助器时,如下所示:

visit orgs_path(reader.org)
我得到这个错误:

 Failure/Error: visit org_path(reader.org)
 ActionController::UrlGenerationError:
   No route matches {:action=>"show", :controller=>"orgs", :format=>nil, :id=>nil, :locale=>#<Org id: 1, name: "Org 1", description: "About org1", website: "", subdomain: "org1", created_at: "2014-12-29 03:33:52", updated_at: "2014-12-29 03:33:52">} missing required keys: [:id]
但我不想重构我所有的规范。发生什么事了

更新 这是我的
routes.rb
,其中我使用了可选的
locale
范围

scope "(/:locale)", :locale =>  /#{I18n.available_locales.join("|")}/ do
  resources :orgs, shallow: true do
    resources :invitations
    resources :memberships, only: [:index, :show, :edit, :update, :destroy]
reader.org
是属于org的
会员资格
工厂的一个实例

我在
rails\u helper.rb中有这个:

RSpec.configure do |config|
  config.include Rails.application.routes.url_helpers
我还将
spec/support/locales.rb
与这些区域设置助手一起包括在内

# see phoet's comment on https://github.com/rspec/rspec-rails/issues/255
# prevents the locale: <#ObjectID> problem where Rails thinks the object is the locale
class ActionView::TestCase::TestController
  def default_url_options(options={})
    get_default_url_options
  end
end

class ActionDispatch::Routing::RouteSet
  def default_url_options(options={})
    get_default_url_options
  end
end

def get_default_url_options
  {
    host: "app.dev",
    locale: I18n.locale || I18n.default_locale
  }
end
#参见phoet对https://github.com/rspec/rspec-rails/issues/255
#防止区域设置:Rails认为对象就是区域设置的问题
类ActionView::TestCase::TestController
def default_url_选项(选项={})
获取默认的url选项
结束
结束
类ActionDispatch::Routing::RouteSet
def default_url_选项(选项={})
获取默认的url选项
结束
结束
def get_默认_url_选项
{
主持人:“app.dev”,
语言环境:I18n.locale | | I18n.default_语言环境
}
结束

这是“reader.org”您的应用程序url吗?或者应用程序之外的东西?这似乎与相关,尽管不清楚为什么它在
请求
目录下工作。@PeterAlvin,我想你是对的。查看我的更新。我在
routes.rb
中使用了
scope
,在
spec\u helper.rb
中使用了一些区域设置帮助程序,再次通读一遍,我认为我版本的phoet's monkey patch只适用于请求规范。phoet提供了一个改进的解决方案,但我喜欢deivid rodriguez的
config.before(:each,type::feature){default_url_options[:locale]=I18n.default_locale}
解决方案的简单性和公开性
# see phoet's comment on https://github.com/rspec/rspec-rails/issues/255
# prevents the locale: <#ObjectID> problem where Rails thinks the object is the locale
class ActionView::TestCase::TestController
  def default_url_options(options={})
    get_default_url_options
  end
end

class ActionDispatch::Routing::RouteSet
  def default_url_options(options={})
    get_default_url_options
  end
end

def get_default_url_options
  {
    host: "app.dev",
    locale: I18n.locale || I18n.default_locale
  }
end