Sha256: edf56d64b3afa12caf8e16a8636b2992d4e9b392d7d2c659677a13fd017de35d

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'
require 'sufia/controlled_vocabulary/importer/downloader'

RSpec.describe Sufia::ControlledVocabulary::Importer::Downloader do
  describe '.fetch' do
    let(:url) { 'http://example.org/' }
    let(:output) { double('output') }
    context 'when connection is successful' do
      let(:io) { double('io') }
      let(:stream) { 'foo' }
      before do
        allow(IO).to receive(:copy_stream).with(io, output).and_return(stream)
        allow(described_class).to receive(:open).with(url).and_yield(io)
      end
      it 'returns an IO stream' do
        expect(described_class.fetch(url, output)).to eq stream
      end
    end
    context 'when connection is unsuccessful' do
      let(:exception_io) { double('io', read: '') }
      before do
        allow(described_class).to receive(:open).with(url) do
          raise OpenURI::HTTPError.new('', exception_io)
        end
      end
      it 'raises an exception' do
        expect { described_class.fetch(url, output) }.to raise_error(RuntimeError, "Unable to download from #{url}\n: ")
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sufia-7.4.1 spec/lib/sufia/controlled_vocabulary/importer/downloader_spec.rb
sufia-7.4.0 spec/lib/sufia/controlled_vocabulary/importer/downloader_spec.rb
sufia-7.3.1 spec/lib/sufia/controlled_vocabulary/importer/downloader_spec.rb
sufia-7.3.0 spec/lib/sufia/controlled_vocabulary/importer/downloader_spec.rb
sufia-7.3.0.rc3 spec/lib/sufia/controlled_vocabulary/importer/downloader_spec.rb
sufia-7.3.0.rc2 spec/lib/sufia/controlled_vocabulary/importer/downloader_spec.rb
sufia-7.3.0.rc1 spec/lib/sufia/controlled_vocabulary/importer/downloader_spec.rb