在gemfile中。我已經添加了factory_girls_rails。黃瓜測試期間工廠已經註冊:用戶(FactoryGirl :: DuplicateDefinitionError)
group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl_rails'
end
group :development, :test do
gem 'rspec-rails'
end
在功能/支持/ env.rb
需要從規格/ 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_helper我有要求'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}
現在我得到以下錯誤... PLZ建議我任何機構以及使用這個factories.rb寫步定義。
馬尼什@ Ubuntu的:〜/變更/ test_cucumber $黃瓜功能/ 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
工廠' /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/gem s/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
require' /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
'
在此先感謝。
是的,我通過require'factory_girl_rails'取代了要求「#{Rails.root}/spec/factories」的解決方案。現在它正在工作。謝謝 – manijain