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

The Archive Base Latest Questions

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

We are using RSpec in a rails project for unit testing. I would like

  • 0

We are using RSpec in a rails project for unit testing. I would like to set up some performance tests in RSpec, but do it in a way as to not disrupt the ‘regular’ features and fixtures.

Ideally I’d be able to tag my performance specs in a certain way such that they are not run by default.
Then when I specify to run these specs explicitly it will load a different set of fixtures (it makes sense to do performance testing with a much larger and more ‘production-like’ dataset).

Is this possible? It seems like it should be.

Has anyone set up something like this? How did you go about it?

  • 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-29T11:32:56+00:00Added an answer on May 29, 2026 at 11:32 am

    I managed to get what I was looking for via the following:

    # Exclude :performance tagged specs by default
    config.filter_run_excluding :performance => true
    
    # When we're running a performance test load the test fixures:
    config.before(:all, :performance => true) do
      # load performance fixtures
      require 'active_record/fixtures'
      ActiveRecord::Fixtures.reset_cache
      ActiveRecord::Fixtures.create_fixtures('spec/perf_fixtures', File.basename("products.yml", '.*'))
      ActiveRecord::Fixtures.create_fixtures('spec/perf_fixtures', File.basename("ingredients.yml", '.*'))
    end
    
    # define an rspec helper for takes_less_than
    require 'benchmark'
    RSpec::Matchers.define :take_less_than do |n|
      chain :seconds do; end
      match do |block|
        @elapsed = Benchmark.realtime do
          block.call
        end
        @elapsed <= n
      end
    end
    
    # example of a performance test
    describe Api::ProductsController, "API Products controller", :performance do
      it "should fetch all the products reasonably quickly" do
        expect do
          get :index, :format => :json
        end.to take_less_than(60).seconds
      end
    end
    

    But I tend to agree with Marnen’s point that this isn’t really the best idea for performance testing.

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

Sidebar

Related Questions

I'm retroactively writing some tests, using RSpec, for a Rails project. I'm using the
I am using RSpec, but Rails insists on generating Test::Unit tests. Maybe there is
Configuration: Integration tests for Rails project using RSpec, Capybara, Selemium driver, SQLite database. Situation:
My project is using Rails 3 and RSpec and Capybara for testing. I want
We're working on a Rails 3 project and testing using Capybara/RSpec. The problem is
Its a rails 2.3.5 app. I'm using the rspec and cucumber for testing. When
How can I start using Rspec with an existing Ruby on Rails 2.3.5 project
I'm setting up a Rails 3.1 project and like to properly test it using
I'm using Cucumber with RSpec in a Rails project. When I use the rake
I'm using RSpec for my Rails 3 tests and trying to use Spork. I

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.