Sha256: 9180268e037f518bc6136dfe5a5c0ee5e96dec03ab46429bfa8eaf0f81e5204e

Contents?: true

Size: 1.92 KB

Versions: 17

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

describe GnipApi::Adapter do
  before do
    @uri = URI('http://somwhere.com')
  end

  it 'raises error if no credentials defined' do
    GnipApi.configure do |c|
      c.user = nil
      c.password = nil
      c.account = nil
    end
    expect(Proc.new{GnipApi::Adapter.new}).to raise_error(GnipApi::Errors::MissingCredentials)
  end

  it 'raises error if no adapter is selected' do
    GnipApi.configure do |c|
      c.user = 'somebody'
      c.password = 'something'
      c.account = 'lol'
      c.adapter_class = nil
    end
    
    expect(Proc.new{GnipApi::Adapter.new}).to raise_error(GnipApi::Errors::MissingAdapter)
  end

  it 'does not raise error when credentials and adapter are present' do
    configure_gem
    expect(Proc.new{GnipApi::Adapter.new}).not_to raise_error
  end

  it 'uses adapter selected' do
    configure_gem
    GnipApi.configuration.adapter_class = TestAdapter
    expect(GnipApi::Adapter.new.adapter.class).to eq(TestAdapter)
  end

  describe '#get' do
    before do
      configure_gem
      @adapter = GnipApi::Adapter.new
      @request = GnipApi::Request.new_get(@uri)
    end

    it 'returns a body' do
      result = @adapter.get @request
      expect(result).to eq('get_result') # Defined at spec/lib/test_adapter.rb
    end
  end

  describe '#post' do
    before do
      configure_gem
      @adapter = GnipApi::Adapter.new
      @request = GnipApi::Request.new_post(@uri, 'some_payload')
    end

    it 'returns a body' do
      result = @adapter.post @request
      expect(result).to eq('post_result') # Defined at spec/lib/test_adapter.rb
    end
  end

  describe '#delete' do
    before do
      configure_gem
      @adapter = GnipApi::Adapter.new
      @request = GnipApi::Request.new_delete(@uri, 'some_payload')
    end

    it 'returns a body' do
      result = @adapter.delete @request
      expect(result).to eq('delete_result') # Defined at spec/lib/test_adapter.rb
    end
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
gnip_api-1.1.1 spec/gnip_api/adapter_spec.rb
gnip_api-1.1.0 spec/gnip_api/adapter_spec.rb
gnip_api-1.0.6 spec/gnip_api/adapter_spec.rb
gnip_api-1.0.5 spec/gnip_api/adapter_spec.rb
gnip_api-1.0.4 spec/gnip_api/adapter_spec.rb
gnip_api-1.0.3 spec/gnip_api/adapter_spec.rb
gnip_api-1.0.2 spec/gnip_api/adapter_spec.rb
gnip_api-1.0.1 spec/gnip_api/adapter_spec.rb
gnip_api-1.0.0 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.9 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.8 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.7 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.6 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.5 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.4 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.3 spec/gnip_api/adapter_spec.rb
gnip_api-0.0.2 spec/gnip_api/adapter_spec.rb