我有一个名为EventSeries的模型,它与复数形式相同。我已经将我想象的各种方式添加到了变形器中:
inflect.uncountable %w( fish sheep EventSeries event_series Series series )
我在event_series.yml
中有一个spec/fixtures
fixtures文件。我甚至尝试过添加:
_fixture:
model_class: EventSeries
在yml文件的顶部,但它没有帮助。
我也尝试将文件名更改为event_serieses.yml
并调用event_serieses(:d30_short_series)
,然后我得到NoMethodError undefined method event_serieses
。
我使用RSpec进行测试。在系统规范中,我有以下声明:
let(:subject_series) { event_series(:d30_short_series) }
当我运行规范时,我收到此错误:
NoMethodError: undefined method `event_series' for <RSpec::MySpecFile>
我有许多其他模型,这种模式适用于所有其他模型(使用复数版本,如users
或events
),所以我认为这是一个复数问题。我已经搜索了答案并找到了this issue,这表明问题可以通过将模型名称添加到变形器来解决,但这对我的情况没有帮助。
我设法得到所有其他固有的问题与无数名称的工作;例如,我的路径助手都正常工作,Rails按预期找到我的视图文件。但我无法解决这个夹具问题。
有没有办法将RSpec指向正确的方法来访问我的灯具?
使用Rails 5.2,Ruby 2.6.0和RSpec 3.8。
感谢您分享您的开源项目,调查和解决问题更加简单。
这个specific spec的问题是没有加载所需的灯具。
您有两种方法可以解决此问题。
选项1:在:event_series
中将config.global_fixtures
添加到rails_helper.rb
。
RSpec.configure do |config|
config.global_fixtures = :a, :event_series, ..., :n
选项2:仅在该规格visit_event_series_spec.rb
上加载夹具
RSpec.describe 'visit an event series page' do
fixtures :event_series
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.
我相信你比我更了解为什么页面上没有显示以下事件链接。