Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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 轨道固定装置/不可数模型名称导致命名错误_Ruby On Rails_Rspec_Fixtures_Ruby On Rails 5.2 - Fatal编程技术网

Ruby on rails 轨道固定装置/不可数模型名称导致命名错误

Ruby on rails 轨道固定装置/不可数模型名称导致命名错误,ruby-on-rails,rspec,fixtures,ruby-on-rails-5.2,Ruby On Rails,Rspec,Fixtures,Ruby On Rails 5.2,我有一个名为EventSeries的模型,它的单数形式与复数形式相同。我以我能想象到的各种方式将此添加到拐点: inflect.uncountable %w( fish sheep EventSeries event_series Series series ) 我在spec/fixtures中有一个event\u series.ymlfixtures文件。我甚至尝试添加: _fixture: model_class: EventSeries 在yml文件的顶部,但它没有帮助 我还尝试将

我有一个名为EventSeries的模型,它的单数形式与复数形式相同。我以我能想象到的各种方式将此添加到拐点:

inflect.uncountable %w( fish sheep EventSeries event_series Series series )
我在
spec/fixtures
中有一个
event\u series.yml
fixtures文件。我甚至尝试添加:

_fixture:
  model_class: EventSeries
在yml文件的顶部,但它没有帮助

我还尝试将文件名更改为
event\u series.yml
并调用
event\u series(:d30\u short\u series)
,我得到了
NoMethodError未定义的方法event\u series

我使用RSpec进行测试。在系统规范中,我有以下声明:

let(:subject_series) { event_series(:d30_short_series) }
运行规范时,会出现以下错误:

NoMethodError: undefined method `event_series' for <RSpec::MySpecFile>
NoMethodError:
我有许多其他的模型,这种模式适用于所有其他模型(使用复数版本,如
用户
事件
),因此我假设这是一个复数化问题。我搜索了答案并找到了答案,这表明可以通过将模型名称添加到屈折因子来解决问题,但这对我的情况没有帮助

我设法解决了数不清的名字带来的所有其他固有问题;例如,我的路径助手都工作正常,Rails可以按预期查找我的视图文件。但我还没能解决这个固定装置的问题

是否有办法将RSpec指向访问我的设备的正确方法


使用Rails 5.2、Ruby 2.6.0和RSpec 3.8。

感谢您分享您的开源项目,调查和解决这个问题更简单

问题是没有加载所需的装置

解决这个问题有两种选择

选项1:将
:event_series
添加到您的

RSpec.configure do|config|
config.global_fixtures=:a,:event_series,…:n
选项2:根据该规格加载夹具

RSpec.description“访问事件系列页面”do
固定装置:活动系列
let(:user){users(:third_user)}
那么规范现在将失败,但原因不同:

Failures:

  1) visit an event series page when the user is a visitor when all categories are populated Visit the page
     Failure/Error: expect(page).to have_link(resource.send(attr), href: path)
       expected to find visible link "Dirty 30 Running" but there were no matches. Also found "Dirty 30 Running", which matched the selector but not all filters.

我相信您比我更了解为什么页面上没有显示以下事件链接。

不是答案,抱歉,但仅供参考-Rails 5.2、Ruby 2.6.0和minitest 5.11-工作正常,不需要任何屈折。@smathy只是为了确定,我暂时删除了屈折符,但这没有帮助。因此,问题可能特定于RSpec。
influct.uncountable(%w(设备信息米币品种系列鱼羊牛仔裤警察))
Rails默认包含
系列
。我不确定RSpec的问题,但是EventSeries默认情况下是正确的,您不需要添加任何内容。
event\u series
是否应该是作为全局变量的模型
EventSeries
?您希望
事件系列(:d30\u short\u系列)
做什么?对我来说,事情是如何联系起来的还不清楚,似乎你的假设和解决方案是在一个模型上应用屈折变化,该模型的名称应与单数或复数相同,但如果没有你实施的修复,代码会做什么呢?@DaniloCabello这个应用程序正在使用,在此上下文中,
event_series
是对Rails夹具文件的引用。对于所有其他模型,此语法从fixtures.yml返回一个项。例如,
users(:admin\u user)
从users fixture文件返回一条记录。在这种情况下,
event_series(:d30_short_series)
应该从
event_series.yml
文件返回一个单独的event_series。哇,我真不敢相信我没有想到这一点。我很确定这是一个多元化的问题,我甚至没有检查全球赛程。非常感谢。