RSpec 错误“未初始化的常量 FactoryGirl(名称错误)" [英] RSpec error "Uninitialized constant FactoryGirl (Name Error)"
本文介绍了RSpec 错误“未初始化的常量 FactoryGirl(名称错误)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试运行我的 RSpec 测试:
I try running my RSpec test:
rspec comments.rb
但不断收到相同的错误(见标题).在有人问我之前,我已经将 require factory_girl
添加到 spec_helper.rb.
but keep getting the same error (see title). Before anyone asks I have already added require factory_girl
to spec_helper.rb.
spec/factories/comments.rb
文件的内容是:
FactoryGirl.define do
factory :comment do
comment "MyString"
task_id 1
end
end
这是我包含 factory_girl_rails 的 gemfile 的测试组:
Here is testing group of the gemfile where I included factory_girl_rails:
source 'http://rubygems.org'
...
group :development, :test do
gem 'debugger'
gem 'factory_girl_rails'
gem 'rspec-rails'
end
...
推荐答案
您只需在 spec_helper.rb 文件中添加以下内容
You just have to add the following in your spec_helper.rb file
require 'factory_girl_rails'
这篇关于RSpec 错误“未初始化的常量 FactoryGirl(名称错误)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文