【发布时间】:2012-10-18 18:50:41
【问题描述】:
我在运行测试文件时遇到错误。
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
我的 ruby 版本是 1.8.7 和 rails3.0.1
我的 gemfile 看起来像这样: 组:测试做 宝石“应该” 宝石'factory_girl_rails' 宝石“摩卡” 结束
【问题讨论】:
-
你的工厂文件存储在哪里?
-
它在测试文件/Factories/factories.rb中
标签: ruby-on-rails-3 factory-bot