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

  • SEARCH
  • Home
  • 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 6344019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:33:28+00:00 2026-05-24T20:33:28+00:00

I really like using Factory Girl to setup my tests. I can build chains

  • 0

I really like using Factory Girl to setup my tests. I can build chains of associations in a single line. For example:

Factory.create(:manuscript)

Automatically creates a journal, a journal owner, a manuscript author, etc. It allows me to to keep my setup blocks really simple, and that’s fantastic.

However, there’s a cost of course. Creating several objects in the background means my unit tests are sometimes as long as 0.8 seconds. That’s fine when your app is small, but now I’ve got a few hundred tests and my specs take over a minute to run (not including the time it takes for the app to spin up). It’s starting to feel painful.

I’m not especially interested in anything too drastic, like mocking everything. At least while my app is relatively small, I’d like to maintain my factory girl abstractions. I just want to figure out a way to make them work a bit faster.

Any suggestions?

  • 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-24T20:33:29+00:00Added an answer on May 24, 2026 at 8:33 pm

    Not sure there’s a good solution to this problem. As Beerlington suggested, you can save some time using Factory.build rather than Factory.create. But even that’s not nearly as fast as testing a plain old ruby objects. The fact, it seems, is that factory girl is not a good choice if you’re very concerned with speed.

    That said, I was able to make some fairly significant speed improvements by reading through my entire suite and making liberal use of the rspec-set gem. This allows you to run your setup once — and only once — for the entire group of tests. It’s similar to using before(:all) except that it takes advantage of transactions to reset the state of objects between each spec.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really like how I can easily share files on a network using the
Can anyone explain why using comments like this in css cause really weird effects
I just started using Pantheios and it feels really like a great library for
I've been using MVC frameworks for a short while now and I really like
I've used Trac/Subversion before and really like the integration. My current project is using
I'm using Photologue in my application, and I really like the ManyToManyField selector that
I'm using streetview as an embed in one of my pages. I'd really like
i want to fetch information from the database using objects. i really like this
So I rewrote my paths to something like: URL/really/nice/paths/ using mod_rewrite rules like this:
I'm attempting to create a many-to-many relationship in Redis using Ohm. As an example,

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.