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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:04:39+00:00 2026-06-09T04:04:39+00:00

api = double myApi api.should_receive(:get_info).and_return({ # a 360 lines hash! }) I want to

  • 0
api = double "myApi"
api.should_receive(:get_info).and_return({
  # a 360 lines hash!
})

I want to provide the response that should return from this double.
But this response is a VERY long hash, and I don’t want to clutter my spec file.
Instead I want to write the hash in separate file, and use it in my spec
So, What is the best practices around ?

  • 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-09T04:04:41+00:00Added an answer on June 9, 2026 at 4:04 am

    The best practise would be to not stub out the whole hash. Surely your tests wont require each and every line. You would be better off stubbing out the few lines that each test will need in each test / context.

    If you must stub the whole api, you can create a separate module in spec/support:

    # spec/support/api_stub.rb
    
    module ApiStub
      def self.response
        {
          # hash
        }
      end
    end
    

    Since anything in that folder gets included automatically, you can then use ApiStub.response in your stub definition.

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

Sidebar

Related Questions

I want to provide something like this in my api: class Foobar extends AbstractThing<Double>
I am parsing a JSON response (twitter api - cursor value) and what should
Let's say for example that I want to link java.lang.Double's equals method using a
I've doubled checked my API key is right and that is right I doubled
From the java.text.ChoiceFormat API: setChoices(double[] limits, String[] formats) : Set the choices to be
I am designing a C API which among other things has to provide a
I have method which return the latitude of the location public double[] getlat(){ double
I am trying to deserialize a json response from a google api, so i
I have an API call which returns a double. The double's decimal length can
With the Google Maps JS API v3, I want to drop a marker where

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.