Sha256: 5718427d28eabf1b1d3f14de15ac1888f30acd4de3d17d76ee934aa992ac1ac8

Contents?: true

Size: 1.65 KB

Versions: 8

Compression:

Stored size: 1.65 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 execute delete' do
      response = @http_client.delete('http://httpbin.org/delete')
      expect(response.status).to eq 200
    end

    it 'put 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

    it 'post should raise error 422' do
      expect { @http_client.post('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.34 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.33 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.32 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.30 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.29 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.28 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.27 spec/restful_resource/http_client_spec.rb
restful_resource-0.8.26 spec/restful_resource/http_client_spec.rb