作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Rails 3/factory_girl_rails/Rspec 2 和 Ruby 1.8
我这样定义我的工厂:
Factory.define :user do |u|
u.name 'Some guy'
u.sequence(:email) {|n| "person#{n}@example.com" }
u.password 'password'
end
Factory.define :password_reset_user, :parent => :user do |user|
user.password_reset_key '111222333444'
end
# This will guess the User class
FactoryGirl.define :user do
factory :user do
first_name 'John'
last_name 'Doe'
admin false
end
# This will use the User class (Admin would have been guessed)
factory :admin, :class => User do
first_name 'Admin'
last_name 'User'
admin true
end
# The same, but using a string instead of class constant
factory :admin, :class => 'user' do
first_name 'Admin'
last_name 'User'
admin true
end
end
Factory.define :user do
factory :user do
name 'Some guy'
sequence(:email) {|n| "person#{n}@example.com" }
password 'password'
end
factory :password_reset_user, :parent => :post do
password_reset_key '111222333444'
end
end
undefined method `factory' for main:Object (NoMethodError)
from /Library/Ruby/Gems/1.8/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:56:in `define'
from /web/votropolis/spec/factories.rb:1
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:227:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
from /Library/Ruby/Gems/1.8/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:307:in `find_definitions'
from /Library/Ruby/Gems/1.8/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:305:in `each'
from /Library/Ruby/Gems/1.8/gems/factory_girl-1.3.2/lib/factory_girl/factory.rb:305:in `find_definitions'
from /Library/Ruby/Gems/1.8/gems/factory_girl_rails-1.0/lib/factory_girl_rails/railtie.rb:11
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/lazy_load_hooks.rb:34:in `call'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/application/finisher.rb:46
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:25:in `instance_exec'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:25:in `run'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:50:in `run_initializers'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:49:in `each'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:49:in `run_initializers'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/application.rb:134:in `initialize!'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in `send'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in `method_missing'
from /web/votropolis/config/environment.rb:5
from /web/votropolis/spec/spec_helper.rb:3:in `require'
from /web/votropolis/spec/spec_helper.rb:3
from /web/votropolis/spec/controllers/organizations/memberships_controller_spec.rb:1:in `require'
from /web/votropolis/spec/controllers/organizations/memberships_controller_spec.rb:1
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `autorun'
from /Library/Ruby/Gems/1.8/bin/rspec:19
最佳答案
这是因为此文档仅适用于 FactoryGirl 测试版。不是稳定版。它是在 README 之上的解释。
稳定的文档在这里:http://github.com/thoughtbot/factory_girl/tree/1.3.x
关于ruby-on-rails - 工厂女孩 : How do define a factory without passing parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4043697/
我是一名优秀的程序员,十分优秀!