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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:27:30+00:00 2026-06-03T17:27:30+00:00

I have some expensive test setup that is only necessary for a handful of

  • 0

I have some expensive test setup that is only necessary for a handful of examples in my spec, and, if necessary, it only needs to run once. Because it is slow, I am trying to avoid putting it in a before(:each) block, but before(:all) doesn’t seem to suit my needs. I think a complicating factor is that the expensive part must run AFTER some other common setup. (This is a capybara test for an app with a search engine. After creating some records, I need to index the test database in order to get search results.) My setup is like this:

feature 'some particular feature' do
  before(:each) do
    # a bunch of common test setup (creating records that this test will use)
  end

  describe 'simple example #1' do
    # a simple example that doesn't need the expensive setup
  end
  .
  .
  .
  describe 'simple example #N' do
    # a simple example that doesn't need the expensive setup
  end

  describe 'a more complicated example' do
    before(:all) do
      # expensive_setup that depends on the records created above
    end

    it 'does something' do ... end
    it 'does something else' do ... end
    .
    .
    .
    it 'even does this' do ... end
  end      
end

The problem is that when rspec is running the examples in the context with the more complicated example, the before(:all) block runs before the before(:each) block that it depends on. So far I have had to put the expensive setup in a before(:each) block instead of a before(:all) block. This means that the expensive setup has to run for each it block inside that example. Is there a better way to do this?

Update:
I failed to mention that the result of the expensive operation depends only on the database. Therefore, since each example uses the same database setup, it would be safe to re-use the result of the expensive operation for each example. Also, the result lives in the filesystem, so it won’t be cleared between examples.

I’m thinking the way to go is to put some sort of marker in the filesystem indicating that the result is good and doesn’t need to be re-calculated.


  • 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-06-03T17:27:33+00:00Added an answer on June 3, 2026 at 5:27 pm

    I wound up working around the problem by calculating a digest of the common setup and saving that along with the results of expensive operation. Before doing the expensive operation, check if the current digest matches the one on disk. If so, there is no need to do it. Since all the examples share the common setup, the expensive operation only runs at most once.

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

Sidebar

Related Questions

I have some external Javascript files in my GWT app that I only want
I have some perl code that looks something like this: my @array = map
I have some input elements that the users are request special behavior on pageup
I have some UIViews that have different centers and transforms applied to them. I
I have some images with height=auto because sometimes they are different heights whereas they
I have a long, lazy sequence that I want to reduce and test lazily.
Assume there are potentially expensive operations to be performed in setup or teardown that
Greetings. I have a java method that I consider expensive, and I'm trying to
I have some Clojure code that is simulating and then processing numerical data. The
Say that I have a class like: public class Test { public Func<string, bool>

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.