Sha256: 614432d4c32bec82fc8311c4adb6579b65514ee66a885a21ca9d8c58c629c9e9

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

require_relative '../spec_helper'

describe RestfulResource::HttpClient do
  describe 'Basic HTTP' do
    before :each do
      @http_client = RestfulResource::HttpClient.new
    end

    it 'should execute get' do
      response = @http_client.get('http://httpbin.org/get')
      expect(response.status).to eq 200
    end

    it 'should execute put' do
      response = @http_client.put('http://httpbin.org/put', data: { name: 'Alfred' })
      expect(response.status).to eq 200
    end

    it 'should execute post' do
      response = @http_client.post('http://httpbin.org/post', data: { name: 'Alfred' })
      expect(response.body).to include "name\": \"Alfred"
      expect(response.status).to eq 200
    end

    it 'should raise error 422' do
      expect { @http_client.put('http://httpbin.org/status/422', data: { name: 'Mad cow' }) }.to raise_error(RestfulResource::HttpClient::UnprocessableEntity)
    end
  end

  describe 'Authentication' do
    before :each do
      auth = RestfulResource::Authorization.http_authorization('user', 'passwd')
      @http_client = RestfulResource::HttpClient.new(authorization: auth)
    end

    it 'should execute authenticated get' do
      response = @http_client.get('http://httpbin.org/basic-auth/user/passwd')
      expect(response.status).to eq 200
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
restful_resource-0.8.21 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.20 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.19 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.18 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.17 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.16 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.15 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.14 spec/restful_resource/http_client_spec.rb