FactoryGirl错误:rspec

时间:2014-01-07 06:06:02

标签: ruby-on-rails rspec ruby-on-rails-4 factory-bot

从Github合并我的代码后,我无法运行rpsec。

我一直收到FactoryGirl错误: uninitialized constant ControllerMacros::FactoryGirl
1) Question has a valid factory
Failure/Error: expect(FactoryGirl.build(:question)).to be_valid
NameError:
uninitialized constant FactoryGirl
# ./spec/models/question_spec.rb:14:in `block (2 levels) in '

请帮忙。

2 个答案:

答案 0 :(得分:2)

看来FactoryGirl可能缺少一些定义。 spec_helper中的Try declaring the following

# spec/spec_helper.rb
require 'factory_girl'
FactoryGirl.find_definitions 

答案 1 :(得分:0)

如果这是针对Rails项目的,您可以使用factory_girl_rails手动查找定义,这将自动为您加载定义。