在宝石文件中。我添加了 factory_girls_rails。
group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl_rails'
end
group :development, :test do
gem 'rspec-rails'
end
在 features/support/env.rb 需要来自 spec/factories.rb 的工厂
require 'cucumber/rails'
require "#{Rails.root}/spec/factories"
在规范/factories.rb
FactoryGirl.define do
factory :user do
first_name "John"
last_name "Doe"
admin false
end
end
在 spec/spec_helper 我需要 require 'factory_girl_rails'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl_rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
现在我得到了以下错误...请建议我任何机构以及编写步骤定义以使用此 factory.rb。
manish@ubuntu:~/change/test_cucumber$ cucumber features/sign_up.feature 工厂已经注册:用户 (FactoryGirl::DuplicateDefinitionError) /home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2 .0/lib/factory_girl /decorator.rb:10:in method_missing'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl/decorator/disallows_duplicates_registry.rb:6:in
register' /home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl.rb:65:在block in register_factory'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl.rb:64:in
每个'/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl.rb:64:in register_factory'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb:20:in
factory'/home/manish/change/test_cucumber/spec /factories.rb:2:in block in <top (required)>'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb:49:in
instance_eval' /home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb:49:in run'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb:7:in
define ' /home/manish/change/test_cucumber/spec/factories.rb:1:in<top (required)>'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in
需要'/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in block in require'
/home/manish/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in
load_dependency'/home/manish/.rvm/gems /ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in require'
/home/manish/change/test_cucumber/features/support/env.rb:8:in
'
提前致谢。