title: How to stub static class methods through rspec
body: <p>I have a static method which initiates a static variable by making a external service call. I want to stub that static method call so that external service call is not made while initializing of the class variable.
  here is an example of my code in simple terms.</p>
  
  <pre><code>class ABC
      def self.ini
          return someCallToMyExternalLibrary # i don't want the execution to go there while testing
      end
  
      @@config = self.ini
  
      def method1
          return @@config['download_URL']
      end
  end
  </code></pre>
  
  <p>Now I want to stub the static method call with my object so that @@config is initialized with the response which I want to get.
  I have tried several things and I seems that @@config is not initialized with my object but by the implemented call only.</p>
  
  <pre><code>describe ABC do
      let(:myObject) { Util.jsonFromFile("/data/app_config.json")}
      let(:ABC_instance) { ABC.new }
  
      before(:each) do
          ABC.stub(:ini).and_return(myObject)
      end
  
      it "check the download url" do
          ABC_instance.method1.should eql("download_url_test")
          # this test fails as @@config is not getting initialized with my object
          # it returns the download url as per the implementation.
      end
  
  end
  </code></pre>
  
  <p>I have even tried stubing in the spec_helper with the though that it will be executed first before the class variable is initialized when execution reaches there, but that also did not help. I am stuck with this now for a while. Someone please be a Savior.</p>