Sha256: 7594092f3508d179cf1b1aac6f6179c9ad811374c070e54cb8409e2030af0f24

Contents?: true

Size: 1.68 KB

Versions: 29

Compression:

Stored size: 1.68 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

describe "EyApi" do
  describe "#get_json" do
    before(:each) do
      @api = Object.new
      @api.instance_variable_set("@rest", RestClient::Resource.new('http://example.org'))
      @api.instance_variable_set("@env", @mock_environment_name)
      @api.instance_variable_set("@keys", {})
      @api.extend(EyApi)

      @api.stub!(:sleep)
    end

    after(:each) do
      FakeWeb.clean_registry
    end

    describe "when the JSON is available" do
      before(:each) do
        FakeWeb.register_uri(:post, "http://example.org/api/json_for_instance", :body => JSON.generate({:valid => "json"}))
      end

      it "should pass through exceptions that it receives" do
        JSON.stub!(:parse).and_raise(Exception)
        lambda {
          @api.get_json("i-decafbad")
        }.should raise_error
      end

      it "should return a valid JSON structure" do
        presumably_valid_json = @api.get_json("i-feedface")
        lambda {
          JSON[presumably_valid_json]
        }.should_not raise_error
      end
    end

    describe "when the JSON is not yet available" do
      
      it "should retry until the 503 goes away" do
        FakeWeb.register_uri(:post, "http://example.org/api/json_for_instance", [{
            :status => ["503", "Service Unavailable"],
            :body => "{}",
          }, {
            :status => ["503", "Service Unavailable"],
            :body => "{}",
          }, {
            :status => ["200", "OK"],
            :body => JSON.generate({:valid => 'json'}),
          }]
        )

        lambda {
          JSON[@api.get_json("i-robot")]
        }.should_not raise_error
      end
      
    end
  end
end


Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ey_cloud_server-1.5.0 spec/ey_api_spec.rb
ey_cloud_server-1.4.61 spec/ey_api_spec.rb
ey_cloud_server-1.4.60 spec/ey_api_spec.rb
ey_cloud_server-1.4.58 spec/ey_api_spec.rb
ey_cloud_server-1.4.54 spec/ey_api_spec.rb
ey_cloud_server-1.4.51 spec/ey_api_spec.rb
ey_cloud_server-1.4.50 spec/ey_api_spec.rb
ey_cloud_server-1.4.49 spec/ey_api_spec.rb
ey_cloud_server-1.4.47a spec/ey_api_spec.rb
ey_cloud_server-1.4.47 spec/ey_api_spec.rb
ey_cloud_server-1.4.46 spec/ey_api_spec.rb
ey_cloud_server-1.4.45 spec/ey_api_spec.rb
ey_cloud_server-1.4.44 spec/ey_api_spec.rb
ey_cloud_server-1.4.43 spec/ey_api_spec.rb
ey_cloud_server-1.4.42 spec/ey_api_spec.rb
ey_cloud_server-1.4.41 spec/ey_api_spec.rb
ey_cloud_server-1.4.40 spec/ey_api_spec.rb
ey_cloud_server-1.4.39 spec/ey_api_spec.rb
ey_cloud_server-1.4.37 spec/ey_api_spec.rb
ey_cloud_server-1.4.37.ruby19 spec/ey_api_spec.rb