作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我已经完成了看似所有正确的步骤,但我仍然收到此错误。来自 gem 文件:
group :test do
gem 'rspec-rails'
gem 'shoulda-matchers', require: false
gem 'database_cleaner'
gem 'factory_girl_rails', '~> 4.0', require: false
gem 'faker'
end
spec_helper.rb:
require 'factory_girl_rails'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
FactoryGirl.definition_file_paths = [File.expand_path('../factories', __FILE__)]
FactoryGirl.find_definitions
FactoryGirl.factories.clear
end
规范/工厂/公司.rb: 需要'spec_helper' 需要'伪造者'
FactoryGirl.define do
factory :company do
name { Faker::Name.name }
system_name { Faker::Company.name }
domain { Faker::Internet.url }
end
end
公司规范.rb: 需要'spec_helper'
describe 'Company' do
it 'has a valid factory' do
FactoryGirl.build(:company).should be_valid
end
end
获取错误失败/错误:
Failure/Error: FactoryGirl.create(:company).should be_valid
ArgumentError:
Factory not registered: company
最佳答案
我把所有的东西都放错了地方:
gemfile 需要:
group :development, :test do
gem 'rspec-rails'
gem 'shoulda-matchers', require: false
gem 'database_cleaner'
gem 'factory_girl_rails', '~> 4.0', require: false
gem 'faker'
end
我将 spec_helper 中的所有内容移至 rails_helper.rb 并去掉了两行:
require 'factory_girl_rails'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
FactoryGirl.definition_file_paths = [File.expand_path('../factories', __FILE__)]
// FactoryGirl.find_definitions // got rid of this
// FactoryGirl.factories.clear // got rid of this
end
公司规范.rb:
require 'rails_helper'
describe 'Company' do
it 'has a valid factory' do
expect(build(:company)).to be_valid
end
end
大部分信息来自评论并源自此 tutorial关于 rspec 和工厂女孩。
关于ruby-on-rails - 工厂女孩争论错误 : Factory not registered:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31823022/
我是一名优秀的程序员,十分优秀!