在Factory Girl getting started documentation中它表示要包含这样的辅助模块:
# RSpec
# spec/support/factory_girl.rb
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
RSpec配置块内部。但这对我不起作用。我只是将模块包含放在rails_helper.rb
的开头,它工作正常。
我的问题是为什么文档说要把它放在配置块中?这有用吗?我是否会遇到方法碰撞。我是否反对最佳做法?
答案 0 :(得分:1)
默认情况下不会加载驻留在spec / support中的文件。对于Rails 4.2,取消注释spec / rails_helper.rb中的第21行。