spec/lib/aipp/downloader_spec.rb in aipp-0.2.4 vs spec/lib/aipp/downloader_spec.rb in aipp-0.2.5

- old
+ new

@@ -5,71 +5,71 @@ Pathname(__FILE__).join('..', '..', '..', 'fixtures') end let :tmp_dir do Pathname(Dir.mktmpdir).tap do |tmp_dir| - (archives_dir = tmp_dir.join('archives')).mkpath - FileUtils.cp(fixtures_dir.join('archive.zip'), archives_dir) + (sources_dir = tmp_dir.join('sources')).mkpath + FileUtils.cp(fixtures_dir.join('source.zip'), sources_dir) end end after do FileUtils.rm_rf(tmp_dir) end describe :read do - context "archive does not exist" do - it "creates the archive" do + context "source archive does not exist" do + it "creates the source archive" do Spy.on(Kernel, open: File.open(fixtures_dir.join('new.html'))) - subject = AIPP::Downloader.new(storage: tmp_dir, archive: 'new-archive') do |downloader| - File.exist?(tmp_dir.join('work')).must_equal true + subject = AIPP::Downloader.new(storage: tmp_dir, source: 'new-source') do |downloader| + _(File.exist?(tmp_dir.join('work'))).must_equal true downloader.read(document: 'new', url: 'http://localhost/new.html') end - zip_entries(subject.archive_file).must_equal %w(new.html) - subject.send(:archives_path).children.count.must_equal 2 + _(zip_entries(subject.source_file)).must_equal %w(new.html) + _(subject.send(:sources_path).children.count).must_equal 2 end end - context "archive does exist" do - it "unzips and uses the archive" do + context "source archive does exist" do + it "unzips and uses the source archive" do Spy.on(Kernel, open: File.open(fixtures_dir.join('new.html'))) - subject = AIPP::Downloader.new(storage: tmp_dir, archive: 'archive') do |downloader| - File.exist?(tmp_dir.join('work')).must_equal true + subject = AIPP::Downloader.new(storage: tmp_dir, source: 'source') do |downloader| + _(File.exist?(tmp_dir.join('work'))).must_equal true downloader.read(document: 'new', url: 'http://localhost/new.html').tap do |content| - content.must_be_instance_of Nokogiri::HTML5::Document - content.text.must_match /fixture-html-new/ + _(content).must_be_instance_of Nokogiri::HTML5::Document + _(content.text).must_match /fixture-html-new/ end end - zip_entries(subject.archive_file).must_equal %w(new.html one.html two.html) - subject.send(:archives_path).children.count.must_equal 1 + _(zip_entries(subject.source_file)).must_equal %w(new.html one.html two.html) + _(subject.send(:sources_path).children.count).must_equal 1 end it "downloads HTML documents to Nokogiri::HTML5::Document" do Spy.on(Kernel, open: File.open(fixtures_dir.join('new.html'))) - AIPP::Downloader.new(storage: tmp_dir, archive: 'archive') do |downloader| + AIPP::Downloader.new(storage: tmp_dir, source: 'source') do |downloader| downloader.read(document: 'new', url: 'http://localhost/new.html').tap do |content| - content.must_be_instance_of Nokogiri::HTML5::Document - content.text.must_match /fixture-html-new/ + _(content).must_be_instance_of Nokogiri::HTML5::Document + _(content.text).must_match /fixture-html-new/ end end end it "downloads and caches PDF documents to AIPP::PDF" do Spy.on(Kernel, open: File.open(fixtures_dir.join('new.pdf'))) - AIPP::Downloader.new(storage: tmp_dir, archive: 'archive') do |downloader| + AIPP::Downloader.new(storage: tmp_dir, source: 'source') do |downloader| downloader.read(document: 'new', url: 'http://localhost/new.pdf').tap do |content| - content.must_be_instance_of AIPP::PDF - content.text.must_match /fixture-pdf-new/ + _(content).must_be_instance_of AIPP::PDF + _(content.text).must_match /fixture-pdf-new/ end end end it "downloads explicitly specified type" do Spy.on(Kernel, open: File.open(fixtures_dir.join('new.pdf'))) - AIPP::Downloader.new(storage: tmp_dir, archive: 'archive') do |downloader| + AIPP::Downloader.new(storage: tmp_dir, source: 'source') do |downloader| downloader.read(document: 'new', url: 'http://localhost/new', type: :pdf).tap do |content| - content.must_be_instance_of AIPP::PDF - content.text.must_match /fixture-pdf-new/ + _(content).must_be_instance_of AIPP::PDF + _(content.text).must_match /fixture-pdf-new/ end end end end end