Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4041800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:55:32+00:00 2026-05-20T12:55:32+00:00

I have some seed data (for price ranges) that is the same in prod,

  • 0

I have some seed data (for price ranges) that is the same in prod, dev, test and doesn’t change. I need that data in my test db to run my cuke tests.

I am load my seed data into test DB before the scenario loads, but it’s failing.

I have the following in my features/support/env.rb file

# from http://www.andhapp.com/blog/2009/11/07/using-factory_girl-with-cucumber/
Before do
    require 'factory_girl_rails'
    # Dir.glob(File.join(File.dirname(__FILE__), '../../spec/factories/*.rb')).each {|f| require f }
    Dir.glob(File.join(File.dirname(__FILE__), '../../db/seeds.rb')).each {|f| require f }
end

Which loads the following file:

# wipe out all previous data
Price.delete_all #is there a factory way of doing this?
# set defaults
Factory.define :price do |price|
  price.id                  1
  price.price_range         "$100"
end

# insert seed data
@price = Factory(:price, :id => 1, :price_range => "$100 - $500")
@price = Factory(:price, :id => 2, :price_range => "$500 - $1,000")
@price = Factory(:price, :id => 3, :price_range => "$1,000 - $1,000")
@price = Factory(:price, :id => 4, :price_range => "$10,000 - $100,000")

I get the following error message:

Factory already defined: price (Factory::DuplicateDefinitionError)
 /Library/Ruby/Gems/1.8/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:61:in `define'
 /Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/../../db/seeds.rb:16
 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:227:in `load_dependency'
 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
 /Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/env.rb:92
 /Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/env.rb:92:in `each'
 /Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/env.rb:92:in `Before'

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:55:33+00:00Added an answer on May 20, 2026 at 12:55 pm

    You can only call Factory.define :price once, and I would probably not put it in the file that it’s in right now. Do you have a factories folder? It usually lives in spec/factories. In there I would create the file price.rb, and define your factory once, there. factory_girl should automatically load all of those definitions up for you once.

    If you’re using Rails3 and you have factory_girl_rails in your Gemfile, then you don’t even need that require 'factory_girl_rails', it does it for you.

    Also if you have a new-ish version of cucumber the installer should automatically have added this section for you in env.rb:

    if defined?(ActiveRecord::Base)
      begin
        require 'database_cleaner'
        DatabaseCleaner.strategy = :truncation
      rescue LoadError => ignore_if_database_cleaner_not_present
      end
    end
    

    DatabaseCleaner is a good way to do the truncation instead of using your Price.delete_all

    The last thing is seeds.rb – It’s a good concept and something very similar to what we do in one of our apps at work.

    But keep in mind, everything in the features/support directory is automatically required by cucumber, so you don’t need to have that Dir.glob nonsense.

    With factory_girl we don’t use the default rails seeds file because it’s not really applicable (in our opinion).

    I would just add a file named anything (ours is named db_setup.rb) that looks something like this:

    Before do
      # Truncates the DB before each Scenario,
      # make sure you've added database_cleaner to your Gemfile.
      DatabaseCleaner.clean
    
      Factory(:price, :attr1 => 'blah'...)
      # More factories here etc
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some input data that sometimes appears with &nbsp characters on the end.
I have some kind of test data and want to create a unit test
I have some UI in VB 2005 that looks great in XP Style, but
We have some files on our website that users of our software can download.
I have seen some apps that have a few rake tasks included to load
Have some audio and video files that users are to download, however depending on
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some classes layed out like this class A { public virtual void
I have some C# / asp.net code I inherited which has a textbox which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.