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