Sha256: 5e3fdde2adfe108da1cc26c4860b154e617a17e163cee7a8ec6cbafcd4ea2fa1

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe UsdaNutrientDatabase::Import::Downloader do
  let(:downloader) { described_class.new('tmp/usda') }
  let(:extraction_path) { "#{directory}/#{version}" }
  let(:directory) { 'tmp/usda' }
  let(:version) { 'sr25' }
  let(:filenames) do
    [
      'DATA_SRC.txt', 'DATSRCLN.txt', 'DERIV_CD.txt', 'FD_GROUP.txt',
      'FOOD_DES.txt', 'FOOTNOTE.txt', 'LANGDESC.txt', 'LANGUAL.txt',
      'NUTR_DEF.txt', 'NUT_DATA.txt', 'SRC_CD.txt', 'WEIGHT.txt', 'sr25_doc.pdf'
    ]
  end

  describe '#download_and_unzip' do
    before do
      stub_request(:get, /.*/).
        to_return(body: File.read('spec/support/sr25.zip'))
      downloader.download_and_unzip
    end

    after { downloader.cleanup }

    it 'should download and extract all files' do
      filenames.each do |filename|
        expect(File.exist?("#{extraction_path}/#{filename}")).to eql(true)
      end
    end
  end

  describe '#cleanup' do
    before do
      stub_request(:get, /.*/).
        to_return(body: File.read('spec/support/sr25.zip'))
      downloader.download_and_unzip
      downloader.cleanup
    end

    it 'should remove all of the extracted files' do
      filenames.each do |filename|
        expect(File.exist?("#{extraction_path}/#{filename}")).to eql(false)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
usda-nutrient-database-1.1.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-1.0.1 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-1.0.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.8.1 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.8.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.7.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.6.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.5.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.4.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.3.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.2.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.1.2 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.1.1 spec/lib/usda_nutrient_database/import/downloader_spec.rb
usda-nutrient-database-0.1.0 spec/lib/usda_nutrient_database/import/downloader_spec.rb