spec/extractor_spec.rb in oddb2xml-2.2.7 vs spec/extractor_spec.rb in oddb2xml-2.2.8

- old
+ new

@@ -2,45 +2,56 @@ require 'spec_helper' require "#{Dir.pwd}/lib/oddb2xml/downloader" ENV['TZ'] = 'UTC' # needed for last_change LAST_CHANGE = "2015-07-03 00:00:00 +0000" -NR_PACKS = 23 +NR_PACKS = 24 +def common_before + @savedDir = Dir.pwd + Dir.chdir(Oddb2xml::WorkDir) + VCR.eject_cassette; VCR.insert_cassette('oddb2xml') +end + +def common_after + VCR.eject_cassette + Dir.chdir(@savedDir) if @savedDir and File.directory?(@savedDir) +end + describe Oddb2xml::LppvExtractor do before(:all) { - VCR.eject_cassette; VCR.insert_cassette('oddb2xml') + common_before @downloader = Oddb2xml::LppvDownloader.new @content = @downloader.download @lppvs = Oddb2xml::LppvExtractor.new(@content).to_hash } - after(:all) { VCR.eject_cassette } + after(:all) { common_after } it "should have at least one item" do expect(@lppvs.size).not_to eq 0 end end describe Oddb2xml::MigelExtractor do before(:all) { - VCR.eject_cassette; VCR.insert_cassette('oddb2xml') + common_before @downloader = Oddb2xml::MigelDownloader.new xml = @downloader.download @items = Oddb2xml::MigelExtractor.new(xml).to_hash } - after(:all) { VCR.eject_cassette } + after(:all) { common_after } it "should have at some items" do expect(@items.size).not_to eq 0 expect(@items.find{|k,v| 3248410 == v[:pharmacode] }).not_to be_nil expect(@items.find{|k,v| /Novopen/i.match(v[:desc_de]) }).not_to be_nil expect(@items.find{|k,v| 3036984 == v[:pharmacode] }).not_to be_nil expect(@items.find{|k,v| /Epimineral/i.match(v[:desc_de]) }).not_to be_nil end end describe Oddb2xml::RefdataExtractor do - before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } - after(:all) { VCR.eject_cassette } + before(:all) { common_before } + after(:all) { common_after } @@last_change = '2015-11-24 00:00:00 +0000' context 'should handle pharma articles' do subject do @downloader = Oddb2xml::RefdataDownloader.new({}, :pharma) @@ -94,12 +105,12 @@ end end end describe Oddb2xml::BagXmlExtractor do - before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } - after(:all) { VCR.eject_cassette } + before(:all) { common_before } + after(:all) { common_after } context 'should handle articles with and without pharmacode' do subject do dat = File.read(File.join(Oddb2xml::SpecData, 'Preparations.xml')) Oddb2xml::BagXmlExtractor.new(dat).to_hash end @@ -127,12 +138,12 @@ end end end describe Oddb2xml::SwissmedicInfoExtractor do - before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } - after(:all) { VCR.eject_cassette } + before(:all) { common_before } + after(:all) { common_after } include ServerMockHelper before(:each) do @downloader = Oddb2xml::SwissmedicInfoDownloader.new end context 'builds fachfinfo' do @@ -151,12 +162,12 @@ } end end describe Oddb2xml::SwissmedicExtractor do - before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml'); cleanup_directories_before_run } - after(:all) { VCR.eject_cassette } + before(:all) { common_before; cleanup_directories_before_run } + after(:all) { common_after } context 'when transfer.dat is empty' do subject { Oddb2xml::SwissmedicInfoExtractor.new("") } it { expect(subject.to_hash).to be_empty } end context 'can parse swissmedic_package.xlsx' do @@ -224,12 +235,12 @@ } end end describe Oddb2xml::EphaExtractor do - before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } - after(:all) { VCR.eject_cassette } + before(:all) { common_before } + after(:all) { common_after } context 'can parse epha_interactions.csv' do it { filename = File.join(Oddb2xml::SpecData, 'epha_interactions.csv') string = IO.read(filename) @actions = Oddb2xml::EphaExtractor.new(string).to_arry @@ -237,17 +248,17 @@ } end end describe Oddb2xml::MedregbmExtractor do - # before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } - # after(:all) { VCR.eject_cassette } + # before(:all) { common_before } + # after(:all) { common_after } it "pending" end describe Oddb2xml::ZurroseExtractor do - before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } - after(:all) { VCR.eject_cassette } + before(:all) { common_before } + after(:all) { common_after } context 'when transfer.dat is empty' do subject { Oddb2xml::ZurroseExtractor.new("") } it { expect(subject.to_hash).to be_empty } end context 'when transfer.dat is nil' do