Sha256: b93c7b9a421a23cd4636bf7ba2dd6e91b0fa12bf6cf09cd15da9c49829a2087d

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'
require 'hyrax/controlled_vocabulary/importer/downloader'

RSpec.describe Hyrax::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

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.1.0 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.0.5 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.0.4 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.0.3 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.0.2 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.0.1 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.0.0.rc2 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
hyrax-1.0.0.rc1 spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb
test_hyrax-0.0.1.alpha spec/lib/hyrax/controlled_vocabulary/importer/downloader_spec.rb