Sha256: 9deef422138fc2474742ccbcf679144b6d0090684a0a909c807a3d695c4a5ac4

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe Board::Client do

  let(:client) { Board::Client.new('VALID_KEY') }

  describe "when creating" do
    context 'and missing an API key' do
      it 'should raise an error' do
        expect { Board::Client.new }.to raise_error
      end
    end

    context "with an API key" do
      it 'should not raise an error' do
        Board::Client.new('API_KEY')
      end
    end
  end

  describe "when processing responses" do
    {
      400 => Board::Client::BadRequest,
      401 => Board::Client::Unauthorized,
      403 => Board::Client::Forbidden,
      404 => Board::Client::NotFound,
      406 => Board::Client::NotAcceptable,
      409 => Board::Client::Conflict,
      422 => Board::Client::UnprocessableEntity,
      500 => Board::Client::InternalServerError,
      501 => Board::Client::NotImplemented,
      502 => Board::Client::BadGateway,
      503 => Board::Client::ServiceUnavailable,
    }.each do |code, exception|
      context "when HTTP status code is #{code}" do
        before do
          stub_request(:get, 'http://localhost:3000/api/v1/users/42').
            to_return(:status => code)
        end

        it "raises #{exception.name} error" do
          expect {
            client.users.find(42)
          }.to raise_error(exception)
        end
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
board-client-0.99.1 spec/board/client_spec.rb
board-client-0.99.0 spec/board/client_spec.rb