spec/downloader_spec.rb in oddb2xml-2.2.6 vs spec/downloader_spec.rb in oddb2xml-2.2.7

- old
+ new

@@ -1,7 +1,8 @@ # encoding: utf-8 require 'spec_helper' +require "rexml/document" VCR.eject_cassette # we use insert/eject around each example # not used but, as I still don't know how to generate def filter_aips_xml(filename='AipsDownload_ng.xml', ids_to_keep = [55558, 61848]) @@ -58,11 +59,11 @@ # this takes 5 sec. by call for sleep it 'should count retry times as retrievable or not', :slow => true do expect { Array.new(3).map do Thread.new do - @downloader.send(:retrievable?).should be(true) + expect(@downloader.send(:retrievable?)).to be(true) end end.map(&:join) }.to change { @downloader.instance_variable_get(:@retry_times) }.from(3).to(0) @@ -153,17 +154,17 @@ @xml = @downloader.download end it_behaves_like 'any downloader' context 'when download_by is called' do it 'should parse response hash to xml' do - @xml.should be_a String - @xml.length.should_not == 0 - @xml.should =~ XML_VERSION_1_0 + expect(@xml).to be_a String + expect(@xml.length).not_to eq(0) + expect(@xml).to match(XML_VERSION_1_0) end it 'should return valid xml' do - @xml.should =~ /PHAR/ - @xml.should =~ /ITEM/ + expect(@xml).to match(/PHAR/) + expect(@xml).to match(/ITEM/) end end end context 'NonPharma' do @@ -172,17 +173,17 @@ @downloader = Oddb2xml::RefdataDownloader.new({}, :nonpharma) @xml = @downloader.download end context 'when download_by is ' do it 'should parse response hash to xml' do - @xml.should be_a String - @xml.length.should_not == 0 - @xml.should =~ XML_VERSION_1_0 + expect(@xml).to be_a String + expect(@xml.length).not_to eq(0) + expect(@xml).to match(XML_VERSION_1_0) end it 'should return valid xml' do - @xml.should =~ /NONPHAR/ - @xml.should =~ /ITEM/ + expect(@xml).to match(/NONPHAR/) + expect(@xml).to match(/ITEM/) end end end end @@ -248,18 +249,18 @@ let(:bin) { @downloader.download } it 'should return valid Binary-String' do # unless [:orphan, :package].index(@downloader.type) - bin.should be_a String - bin.bytes.should_not nil + expect(bin).to be_a String + expect(bin.bytes).not_to be nil # end end it 'should clean up current directory' do unless [:orphan, :package].index(@downloader.type) expect { bin }.not_to raise_error - File.exist?('oddb_orphan.xls').should eq(false) + expect(File.exist?('oddb_orphan.xls')).to eq(false) end end end end context 'fridge' do @@ -273,12 +274,12 @@ context 'download_by for fridge xls' do let(:bin) { @downloader.download } it 'should return valid Binary-String' do - bin.should be_a String - bin.bytes.should_not nil + expect(bin).to be_a String + expect(bin.bytes).not_to be nil end end end context 'package' do before(:each) do @@ -291,12 +292,12 @@ context 'download_by for package xls' do let(:bin) { @downloader.download } it 'should return valid Binary-String' do - bin.should be_a String - bin.bytes.should_not nil + expect(bin).to be_a String + expect(bin.bytes).not_to be nil end end end end @@ -331,12 +332,12 @@ let(:csv) { Oddb2xml.add_epha_changes_for_ATC(1, 3) @downloader.download } it 'should read csv as String' do - csv.should be_a String - csv.bytes.should_not nil + expect(csv).to be_a String + expect(csv.bytes).not_to be nil end it 'should clean up current directory' do expect { csv }.not_to raise_error # File.exist?('epha_interactions.csv').should eq(false) end @@ -387,17 +388,17 @@ VCR.use_cassette('oddb2xml', :tag => :bag_xml) do @downloader.download end } it 'should parse zip to string' do - xml.should be_a String - xml.length.should_not == 0 + expect(xml).to be_a String + expect(xml.length).not_to eq(0) end it 'should return valid xml' do - xml.should =~ XML_VERSION_1_0 - xml.should =~ /Preparations/ - xml.should =~ /DescriptionDe/ + expect(xml).to match(XML_VERSION_1_0) + expect(xml).to match(/Preparations/) + expect(xml).to match(/DescriptionDe/) end end end describe Oddb2xml::LppvDownloader do @@ -413,12 +414,12 @@ it_behaves_like 'any downloader' context 'when download is called' do let(:txt) { @downloader.download } it 'should read txt as String' do - @text.should be_a String - @text.bytes.should_not nil + expect(@text).to be_a String + expect(@text.bytes).not_to be nil end end end describe Oddb2xml::MigelDownloader do @@ -433,16 +434,16 @@ it_behaves_like 'any downloader' context 'when download is called' do let(:bin) { @downloader.download } it 'should read xls as Binary-String' do - bin.should be_a String - bin.bytes.should_not nil + expect(bin).to be_a String + expect(bin.bytes).not_to be nil end it 'should clean up current directory' do expect { bin }.not_to raise_error - File.exist?('oddb2xml_files_nonpharma.txt').should eq(false) + expect(File.exist?('oddb2xml_files_nonpharma.txt')).to eq(false) end end end describe Oddb2xml::ZurroseDownloader do @@ -469,16 +470,16 @@ it_behaves_like 'any downloader' context 'when download is called' do let(:dat) { @downloader.download } it 'should read dat as String' do - dat.should be_a String - dat.bytes.should_not nil + expect(dat).to be_a String + expect(dat.bytes).not_to be nil end it 'should clean up current directory' do expect { dat }.not_to raise_error - File.exist?('oddb2xml_zurrose_transfer.dat').should eq(false) + expect(File.exist?('oddb2xml_zurrose_transfer.dat')).to eq(false) end end end describe Oddb2xml::MedregbmDownloader do @@ -526,16 +527,18 @@ after(:each) do common_after end it_behaves_like 'any downloader' context 'download betrieb txt' do let(:txt) { @downloader.download } it 'should return valid String' do - txt.should be_a String - txt.bytes.should_not nil + pending 'Should handle SSL issues' + expect(txt).to be_a String + expect(txt.bytes).not_to be nil end it 'should clean up current directory' do + pending 'Should handle SSL issues' expect { txt }.not_to raise_error - File.exist?('oddb_company.xls').should eq(false) + expect(File.exist?('oddb_company.xls')).to eq(false) end end end context 'person' do @@ -549,16 +552,18 @@ let(:txt) { # this downloads a xlsx file (2.5MB), where we should keep only the first few lines @downloader.download } it 'should return valid String' do - txt.should be_a String - txt.bytes.should_not nil + pending 'Should handle SSL issues' + expect(txt).to be_a String + expect(txt.bytes).not_to be nil end it 'should clean up current directory' do + pending 'Should handle SSL issues' expect { txt }.not_to raise_error - File.exist?('oddb_person.xls').should eq(false) + expect(File.exist?('oddb_person.xls')).to eq(false) end end end end @@ -592,20 +597,20 @@ after(:all) do common_after end it_behaves_like 'any downloader' context 'when download is called' do let(:xml) { @downloader.download } it 'should parse zip to String' do - xml.should be_a String - xml.length.should_not == 0 + expect(xml).to be_a String + expect(xml.length).not_to eq(0) end it 'should return valid xml' do - xml.should =~ XML_VERSION_1_0 - xml.should =~ /medicalInformations/ - xml.should =~ /content/ + expect(xml).to match(XML_VERSION_1_0) + expect(xml).to match(/medicalInformations/) + expect(xml).to match(/content/) end it 'should clean up current directory' do expect { xml }.not_to raise_error - File.exist?('swissmedic_info.zip').should eq(false) + expect(File.exist?('swissmedic_info.zip')).to eq(false) end end end