Sha256: e059996812a4c1ffdfd41c87048ea7697b04eec6fbc6335a1ef87ffa8e7c4eb5

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'test_helper'
require 'hyperclient'

describe Hyperclient do
  describe 'new' do
    it 'creates a new EntryPoint with the url' do
      Hyperclient::EntryPoint.expects(:new).with('http://api.example.org')

      Hyperclient.new('http://api.example.org')
    end

    describe 'with an optional block' do
      let(:client) do
        Hyperclient.new('http://api.example.org') do |client|
          client.connection(default: true) do |conn|
            conn.use Faraday::Request::Instrumentation
          end
          client.headers['Access-Token'] = 'token'
        end
      end

      it 'creates a Faraday connection with the default and additional headers' do
        _(client.headers['Content-Type']).must_equal 'application/hal+json'
        _(client.headers['Accept']).must_equal 'application/hal+json,application/json'
        _(client.headers['Access-Token']).must_equal 'token'
      end

      it 'creates a Faraday connection with the entry point url' do
        _(client.connection.url_prefix.to_s).must_equal 'http://api.example.org/'
      end

      it 'creates a Faraday connection with the default block plus any additional handlers' do
        handlers = client.connection.builder.handlers
        _(handlers).must_include Faraday::Request::Instrumentation
        _(handlers).must_include Faraday::Response::RaiseError
        _(handlers).must_include Faraday::FollowRedirects::Middleware
        _(handlers).must_include Faraday::HalJson::Request
        _(handlers).must_include Faraday::HalJson::Response
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hyperclient-2.0.0 test/hyperclient_test.rb