Rspec Factory Girl模型奇异复数(未初始化常数[ModelName])

时间:2012-08-14 06:50:23

标签: ruby-on-rails ruby rspec

当我尝试测试名为“设置”的模型时出错,我觉得它与单数和复数模型名称有关,但我该如何解决?

这是spec settings_spec.rb:

require 'spec_helper'

describe Settings do
  let!(:settings) { Factory(:settings) }

  describe "has a valid factory" do
    specify { should be_an_instance_of(Settings) }
  end

end


1) Settings has a valid factory 
     Failure/Error: let!(:settings) { Factory(:settings) }
     NameError:
       uninitialized constant Setting
     # ./spec/models/settings_spec.rb:4:in `block (2 levels) in <top (required)>'

我的模型名为Settings,文件名为settings.rb。谢谢!

1 个答案:

答案 0 :(得分:1)

它希望模型名称为Setting。将模型app/model/setting.rb重命名为Setting或转到文件config/initializers/inflections.rb,然后将设置添加到不可数配置中。

ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable %w(settings)
end