运行测试文件时出现错误。
factory.rb:334:in `factory_by_name': No such factory: user (ArgumentError)
我有用户模型,但为什么仍然出现此错误?我的 factory.rb 包含:
FactoryGirl.define do
factory :user do |u|
u.sequence(:email) {|n| "#{n}@email.com"}
u.login 'Joe'
u.password 'password'
u.password_confirmation 'password'
u.phone '1111111111'
u.gender 'F'
u.active '1'
u.social_profile_active '1'
end
end
在test_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'factory_girl'
#Factory.find_definitions
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
#fixtures :all
# Add more helper methods to be used by all tests here...
end
我的红宝石版本是 1.8.7 和 rails3.0.1
我的 gemfile 看起来像这样: group :test do gem 'should' gem 'factory_girl_rails' gem 'mocha' end