Sha256: 86a90e6b965f144df0310fb29d562076befcf8f6ef8c8fdf3b6c166a76c131fb

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Acfs::Request do
  let(:url)     { 'http://api.example.org/v1/examples' }
  let(:headers) { nil }
  let(:params)  { nil }
  let(:data)    { nil }
  let(:method)  { :get }
  let(:options) { {method: method, headers: headers, params: params, data: data} }
  let(:request) { Acfs::Request.new(url, options) }

  describe '#url' do
    it 'should return request URL' do
      expect(request.url).to be == url
    end

    context 'with parameters' do
      let(:params) { {id: 10} }

      it 'should return URL without query' do
        expect(request.url).to be == url.to_s
      end
    end
  end

  describe '#headers' do
    let(:headers) { {'Accept' => 'application/json'} }

    it 'should return request headers' do
      expect(request.headers).to be == headers
    end
  end

  describe '#method' do
    context 'when nil given' do
      let(:method) { nil }

      it 'should default to :get' do
        expect(request.method).to be == :get
      end
    end

    it 'should return request method' do
      expect(request.method).to be == method
    end
  end

  describe '#params' do
    let(:params) { {id: 10} }

    it 'should return request headers' do
      expect(request.params).to be == params
    end
  end

  describe '#data' do
    let(:data) { {id: 10, name: 'Anon'} }

    it 'should return request data' do
      expect(request.data).to be == data
    end
  end

  describe '#data' do
    context 'with data' do
      let(:data) { {id: 10, name: 'Anon'} }

      it { expect(request).to be_data }
    end

    context 'without data' do
      let(:data) { nil }

      it { expect(request).to_not be_data }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acfs-1.5.1 spec/acfs/request_spec.rb
acfs-1.5.0 spec/acfs/request_spec.rb
acfs-1.4.0 spec/acfs/request_spec.rb
acfs-1.3.4 spec/acfs/request_spec.rb