factory_girl 未定义方法“保存!”为了

factory_girl undefined method `save!' for

## app/models/armor_type.rb
class ArmorType < ActiveRecord::Base
  validates :name, presence: true
...
end

## spec/models/armor_type_spec.rb
require 'rails_helper'
RSpec.describe ArmorType, type: :model do
  it "has a valid name" do
    armor_type = create(:armor_type)
  end
end

## spec/factories/armor_types.rb
FactoryGirl.define do
  factory :armor_type do
    name "cloth"
  end
end

## spec/support/factory_girl.rb
RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
end

## spec/rails_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if     Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'support/factory_girl'
require 'capybara/rspec'

## Gemfile
group :development, :test do
  gem 'byebug'
  gem 'rspec-rails'
  gem 'factory_girl_rails'
end

我似乎无法让 factory_girl 正常工作。我在 testApp 使用 SQLite3 测试数据库创建并且它工作,但是使用我当前使用 PostgreSQL 测试数据库的应用程序我收到以下错误;

          1) ArmorType has a valid name
             Failure/Error: armor_type = create(:armor_type)
             NoMethodError:
               undefined method `save!' for #<ArmorType:0x000000071a8b58 @name="cloth">
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/configuration.rb:14:in `block in initialize'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/evaluation.rb:15:in `[]'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/evaluation.rb:15:in `create'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/strategy/create.rb:12:in `block in result'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/strategy/create.rb:9:in `tap'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/strategy/create.rb:9:in `result'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/factory.rb:42:in `run'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/factory_runner.rb:23:in `block in run'
             # ./.bundle/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/factory_runner.rb:22:in `run'
             # ./.bundle/gems/factory_girl-4.5.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
             # ./spec/models/armor_type_spec.rb:6:in `block (2 levels) in <top (required)>'
             # .bundle/binstubs/rspec:16:in `load'
             # .bundle/binstubs/rspec:16:in `<main>'

我已经使用 PostgreSQL 测试数据库创建了另一个测试应用程序,但我遇到了同样的错误。任何帮助将不胜感激。

干杯!

我在测试的早期阶段无意中创建了一个文件“armor_type.rb”,导致了这个错误。它与 factory_girl、rspec 无关。

新手错误