Sha256: e05871d040c98baffea716a52a616e5f742a74d68bfa50a5a8d07238a6b4559e

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

module Firebrew::AmoApi
  describe Firebrew::AmoApi::Search do
    before do
      response = File.read("spec/fixtures/amo_api/search/#{self.fixture}")
      
      ActiveResource::HttpMock.respond_to do |mock|
        mock.get Search.path(self.params), {}, response
      end
    end
    
    after do
      ActiveResource::HttpMock.reset!
    end
    
    let(:params){{term: 'hoge'}}
    let(:fixture){'base.xml'}
    
    describe '::fetch(params)' do
      subject{Search.fetch self.params}
      
      it { is_expected.to be_instance_of(Array) }
      it { expect(subject.size).to eq(3) }
      
      it 'should construct objects' do
        expect(subject[0].id).to eq('100')
        expect(subject[0].name).to eq('hoge')
        
        expect(subject[1].id).to eq('101')
        expect(subject[1].name).to eq('hoge_fuga')
        
        expect(subject[2].id).to eq('102')
        expect(subject[2].name).to eq('hoge_hoge')
      end
      
      context 'when results were empty' do
        let(:fixture){'empty.xml'}
        it { is_expected.to be_instance_of(Array) }
        it { expect(subject.size).to eq(0) }
      end
      
      context 'when the number of results was one' do
        let(:fixture){'single.xml'}
        
        it { is_expected.to be_instance_of(Array) }
        it { expect(subject.size).to eq(1) }
        
        it 'should construct objects' do
          expect(subject[0].id).to eq('100')
          expect(subject[0].name).to eq('hoge')
        end
      end
    end
    
    describe '::fetch!(params)' do
      subject {Search.fetch! self.params}
      
      it { is_expected.to be_instance_of(Array) }
      it { expect(subject.size).to eq(3) }
      it { expect{subject}.to_not raise_error }
      
      context 'when results were empty' do
        let(:fixture){'empty.xml'}
        it { expect{subject}.to raise_error(Firebrew::ExtensionNotFoundError) }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
firebrew-0.1.3 spec/firebrew/amo_api/search_spec.rb
firebrew-0.1.2 spec/firebrew/amo_api/search_spec.rb
firebrew-0.1.1 spec/firebrew/amo_api/search_spec.rb
firebrew-0.1.0 spec/firebrew/amo_api/search_spec.rb