Sha256: 95ecd5b0c3dcd12744f8a7db305f685a4dfba85a4090205f86af22593e87fa49

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'
require 'httpclient'
require 'gemirro/http'

# Http tests
module Gemirro
  describe 'Http' do
    it 'should return http client' do
      expect(Http.client).to be_a(HTTPClient)
    end

    it 'should raise error when get request failed' do
      uri = 'http://github.com/PierreRambaud'
      Struct.new('HTTPError', :status, :reason)
      result = Struct::HTTPError.new(401, 'Unauthorized')
      allow(Http.client).to receive(:get)
        .once.with(uri, follow_redirect: true).and_return(result)
      expect { Http.get(uri) }
        .to raise_error HTTPClient::BadResponseError, 'Unauthorized'
    end

    it 'should execute get request' do
      uri = 'http://github.com/PierreRambaud'
      Struct.new('HTTPResponse', :status, :body)
      result = Struct::HTTPResponse.new(200, 'body content')
      allow(Http.client).to receive(:get)
        .once.with(uri, follow_redirect: true).and_return(result)

      response = Http.get(uri)
      expect(response).to be_a(Struct::HTTPResponse)
      expect(response.body).to eq('body content')
      expect(response.status).to eq(200)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
gemirro-0.13.5 spec/gemirro/http_spec.rb
gemirro-0.13.4 spec/gemirro/http_spec.rb
gemirro-0.13.3 spec/gemirro/http_spec.rb
gemirro-0.13.2 spec/gemirro/http_spec.rb
gemirro-0.13.1 spec/gemirro/http_spec.rb
gemirro-0.12.0 spec/gemirro/http_spec.rb
gemirro-0.11.0 spec/gemirro/http_spec.rb
gemirro-0.10.5 spec/gemirro/http_spec.rb
gemirro-0.10.4 spec/gemirro/http_spec.rb
gemirro-0.10.3 spec/gemirro/http_spec.rb
gemirro-0.10.2 spec/gemirro/http_spec.rb
gemirro-0.10.1 spec/gemirro/http_spec.rb
gemirro-0.10.0 spec/gemirro/http_spec.rb
gemirro-0.9.1 spec/gemirro/http_spec.rb
gemirro-0.9.0 spec/gemirro/http_spec.rb
gemirro-0.8.1 spec/gemirro/http_spec.rb
gemirro-0.8.0 spec/gemirro/http_spec.rb
gemirro-0.7.0 spec/gemirro/http_spec.rb