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 5957381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:23:34+00:00 2026-05-22T18:23:34+00:00

I am running mysql, database_cleaner, Rspec, etc. I have about 518 tests so far

  • 0

I am running mysql, database_cleaner, Rspec, etc. I have about 518 tests so far and they take 88 seconds to run. This is unacceptable to me as my app development is just beginning.

So before going further, I’d like to try and find ways to reduce the time it takes to run these tests – hopefully without having to actually change the tests.

In most cases, I am trying to use stubs. However, when I am testing models and queries, I do use the database.

I think database_cleaner is slowing them down, but I don’t know how to test queries and stuff without it.

Using sqlite3 with the “:memory:” option only seems to shave off about 10 seconds (kind of disappointing result…)

What can I do to really speed up my tests?

  • 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-22T18:23:35+00:00Added an answer on May 22, 2026 at 6:23 pm

    Ryan Brunner offered a lot of great advice. Everything he said is true in general, yet did not apply to me.

    I didn’t mention Factory Girl because I didn’t think to mention it (don’t ask). It turned out to be very relevant detail because it was responsible for the tests running so slow.

    By simply removing Factory girl completely from my controller tests (I was using Factory.build), I have managed to get them down from 50 seconds to something like 5.

    The reason is that Factory.build calls Factory.create for associations, which causes a database hit… so if you have a lot of associations, it will take awhile to create a new model object. But even more, that only accounted for 30-35% of the overhead in my case. Factory_girl was actually spending 65-70% of its time doing non-database stuff. I have no idea why, but after forcing every call to be Factory.build, it will still taking quite awhile to build my objects. Going with basic MyClass.new ended up being MUCH faster.

    My entire test suite now takes a little under 30 seconds instead of up to 90 seconds. That is a 300% speed increase in general by making these changes… but when it came to the controller tests, I got a 2000% speed increase – and I was already stubbing! All of that performance overhead was due to Factory.build! That is where most of the gains came from.

    Of course, I went back into my models and used Factory.build or simply MyClass.new wherever I could.

    I also added :default_strategy => :build in factories.rb too whenever I could, to prevent Factory Girl from hitting the database. If you ask me, this should be the default as only 1 test failed as a result of this change, but I managed to get 10 entire seconds out of my model tests by this change alone.

    If you’re having problems like I am, follow these steps and you should notice a 2-3x speed improvement with not much drawback.

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

Sidebar

Related Questions

I have a staging Rails site up that's running on MySQL 5.0.32-Debian. On this
I have a number of tests that run against a MySQL database which is
I have a mysql database filled up and running on a Windows computer, is
I am running Ruby and MySQL on a Windows box. I have some Ruby
I have a MySQL instance running locally on port 3306, but for some legacy
On my Unix web server, I have two MySQL database servers running. One on
I'm running a MySQL database locally for development, but deploying to Heroku which uses
I am running a couple of databases on MySQL 5.0.45 and am trying to
I'm running MySQL 5 on a linux server on my local network. Running windows
I am running a mysql server. I would like to somehow make sure that

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.