Sha256: 75484737a4447c60071d92ccb2d6d2a830f88f8db726eb05c91c202defbf0803
Contents?: true
Size: 1.75 KB
Versions: 2
Compression:
Stored size: 1.75 KB
Contents
require 'rest_in_peace/response_converter' require 'ostruct' describe RESTinPeace::ResponseConverter do let(:element1) { { name: 'test1' } } let(:element2) { { name: 'test2' } } let(:response) { OpenStruct.new(body: response_body) } let(:converter) { RESTinPeace::ResponseConverter.new(response, klass) } describe '#result' do subject { converter.result } shared_examples_for 'an array input' do let(:response_body) { [element1, element2] } specify { expect(subject).to be_instance_of(Array) } specify { expect(subject).to eq([OpenStruct.new(name: 'test1'), OpenStruct.new(name: 'test2')]) } end shared_examples_for 'a hash input' do let(:response_body) { element1 } specify { expect(subject).to be_instance_of(OpenStruct) } specify { expect(subject).to eq(OpenStruct.new(name: 'test1')) } end shared_examples_for 'a string input' do let(:response_body) { 'yolo binary stuff' } specify { expect(subject).to be_instance_of(String) } specify { expect(subject).to eq('yolo binary stuff') } end context 'given type is a class' do let(:klass) { OpenStruct } context 'input is an array' do it_behaves_like 'an array input' end context 'input is a hash' do it_behaves_like 'a hash input' end context 'input is a string' do it_behaves_like 'a string input' end end context 'given type is an instance' do let(:klass) { OpenStruct.new } context 'input is an array' do it_behaves_like 'an array input' end context 'input is a hash' do it_behaves_like 'a hash input' end context 'input is a string' do it_behaves_like 'a string input' end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rest-in-peace-1.4.0 | spec/rest_in_peace/response_converter_spec.rb |
rest-in-peace-1.3.1 | spec/rest_in_peace/response_converter_spec.rb |