Sha256: 2c11f26a72949e13958372c86f8e8a545fe443e3205937a50e84df0a83c522af

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe ApiClient do
  describe "#get" do
    context "when response code is 404" do
      before :each do
        FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "404")
      end

      it "should return a NotFound exception" do
        lambda { ApiClient.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::NotFound)
      end
    end

    context "when response code is not 404" do
      before :each do
        FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "201", :body => "User#3333")
      end

      it "should return the response body" do
        ApiClient.get('http://api.example.com/user/5').should == "User#3333"
      end
    end
  end

  describe "#post" do
    context "when response code is 404" do
      before :each do
        FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "404")
      end

      it "should return a NotFound exception" do
        lambda { ApiClient.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::NotFound)
      end
    end

    context "when response code is not 404" do
      before :each do
        FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201", :body => "User#3333")
      end

      it "should return the response body" do
        ApiClient.post('http://api.example.com/user/5', {}).should == "User#3333"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api-client-0.2.0 spec/api_client_spec.rb