Sha256: 61ef3d56350877890eba662afc6ceec50fb313f309e801c158bf374c7483abb0

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

include Restspec::Endpoints
SuperHash = Restspec::Values::SuperHash

describe Response do
  let(:response) { Response.new(200, {}, body) }

  describe '#read_body' do
    subject { response.read_body }

    context 'when the body is a scalar' do
      let(:body) { 'Hello' }
      it { should be_kind_of(String) }
      it { should eq(body) }
    end

    context 'when the body is a hash of scalar values' do
      let(:body) { { x: 1, y: 'string', z: true }.to_json }
      it { should be_kind_of(SuperHash) }
    end

    context 'when the body is an array of scalar values' do
      let(:info) { [1, 'string', true] }
      let(:body) { info.to_json }
      it { should be_kind_of(Array) }
      it { should eq(info) }
    end

    context 'when the body is an array of hashes' do
      let(:info) { [{x: 1}, {x: 2}, {x: 3}] }
      let(:body) { info.to_json }
      it { should be_kind_of(Array) }
      it { should eq(info.as_json) }
    end

    context 'when the body is a hash of array elements' do
      let(:body) { { animals: [ { name: 'Lion' }, { name: 'Elephant' } ], number_of_animals: 2 }.to_json }
      it { should be_kind_of(SuperHash) }
      it { should have_key(:animals) }

      it 'includes an array of SuperHashes' do
        subject.animals.each do |animal|
          expect(animal).to be_kind_of(SuperHash)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
restspec-0.3.2 spec/restspec/endpoints/response_spec.rb
restspec-0.3.1 spec/restspec/endpoints/response_spec.rb
restspec-0.3.0 spec/restspec/endpoints/response_spec.rb
restspec-0.2.6 spec/restspec/endpoints/response_spec.rb
restspec-0.2.5 spec/restspec/endpoints/response_spec.rb
restspec-0.2.4 spec/restspec/endpoints/response_spec.rb
restspec-0.2.3 spec/restspec/endpoints/response_spec.rb
restspec-0.2.2 spec/restspec/endpoints/response_spec.rb
restspec-0.2.1 spec/restspec/endpoints/response_spec.rb
restspec-0.2 spec/restspec/endpoints/response_spec.rb
restspec-0.1 spec/restspec/endpoints/response_spec.rb
restspec-0.0.4 spec/restspec/endpoints/response_spec.rb
restspec-0.0.3 spec/restspec/endpoints/response_spec.rb
restspec-0.0.2 spec/restspec/endpoints/response_spec.rb
restspec-0.0.1 spec/restspec/endpoints/response_spec.rb