spec/libreconv_spec.rb in libreconv-0.9.1 vs spec/libreconv_spec.rb in libreconv-0.9.2
- old
+ new
@@ -1,100 +1,111 @@
-# encoding: utf-8
+# frozen_string_literal: true
+
require 'spec_helper'
describe Libreconv do
+ let(:docx_file) { fixture_path('docx.docx') }
+ let(:doc_file) { fixture_path('doc.doc') }
+ let(:pptx_file) { fixture_path('pptx.pptx') }
+ let(:ppt_file) { fixture_path('ppt.ppt') }
+ let(:target_path) { '/tmp/libreconv' }
+ let(:url) { 'http://s3.amazonaws.com/libreconv-test/docx.docx' }
- before(:all) do
- @docx_file = file_path("docx.docx")
- @doc_file = file_path("doc.doc")
- @pptx_file = file_path("pptx.pptx")
- @ppt_file = file_path("ppt.ppt")
- @target_path = "/tmp/libreconv"
- @url = "http://s3.amazonaws.com/libreconv-test/docx.docx"
+ before do
+ FileUtils.mkdir_p target_path
end
- before(:each) do
- FileUtils.mkdir_p @target_path
+ after do
+ FileUtils.rm_rf target_path
end
- after(:each) do
- FileUtils.rm_rf @target_path
- end
-
describe Libreconv::Converter do
- describe "#new" do
- it "should raise error if soffice command does not exists" do
- expect { Libreconv::Converter.new(@doc_file, "/target", "/Whatever/soffice") }.to raise_error(IOError)
+ describe '#new' do
+ it 'raises error if soffice command does not exists' do
+ expect do
+ Libreconv::Converter.new(
+ doc_file, '/target', '/Whatever/soffice'
+ )
+ end.to raise_error(IOError)
end
- it "should raise error if source does not exists" do
- expect { Libreconv::Converter.new(file_path("nonsense.txt"), "/target") }.to raise_error(IOError)
+ it 'raises error if source does not exists' do
+ expect do
+ Libreconv::Converter.new(
+ fixture_path('nonsense.txt'), '/target'
+ )
+ end.to raise_error(IOError)
end
end
- describe "#convert" do
- it "should convert a docx do pdf specifying target_file" do
- target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
- converter = Libreconv::Converter.new(@doc_file, target_file)
+ describe '#convert' do
+ it 'converts a docx do pdf specifying target_file' do
+ target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
+ converter = Libreconv::Converter.new(doc_file, target_file)
converter.convert
expect(File.file?(target_file)).to eq true
end
- it "should convert a doc to pdf" do
- target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
- converter = Libreconv::Converter.new(@doc_file, @target_path)
+ it 'converts a doc to pdf' do
+ target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
+ converter = Libreconv::Converter.new(doc_file, target_path)
converter.convert
expect(File.file?(target_file)).to eq true
end
- it "should convert a docx to pdf" do
- target_file = "#{@target_path}/#{File.basename(@docx_file, ".docx")}.pdf"
- converter = Libreconv::Converter.new(@docx_file, @target_path)
+ it 'converts a docx to pdf' do
+ target_file = "#{target_path}/#{File.basename(docx_file, '.docx')}.pdf"
+ converter = Libreconv::Converter.new(docx_file, target_path)
converter.convert
expect(File.file?(target_file)).to eq true
end
- it "should convert a pptx to pdf" do
- target_file = "#{@target_path}/#{File.basename(@pptx_file, ".pptx")}.pdf"
- converter = Libreconv::Converter.new(@pptx_file, @target_path)
+ it 'converts a pptx to pdf' do
+ target_file = "#{target_path}/#{File.basename(pptx_file, '.pptx')}.pdf"
+ converter = Libreconv::Converter.new(pptx_file, target_path)
converter.convert
expect(File.file?(target_file)).to eq true
end
- it "should convert a ppt to pdf" do
- target_file = "#{@target_path}/#{File.basename(@ppt_file, ".ppt")}.pdf"
- converter = Libreconv::Converter.new(@ppt_file, @target_path)
+ it 'converts a ppt to pdf' do
+ target_file = "#{target_path}/#{File.basename(ppt_file, '.ppt')}.pdf"
+ converter = Libreconv::Converter.new(ppt_file, target_path)
converter.convert
expect(File.file?(target_file)).to eq true
end
- it "should convert a docx to pdf specifying an URL as source" do
- target_file = "#{@target_path}/docx.pdf"
- converter = Libreconv::Converter.new(@url, @target_path)
- converter.convert
- expect(File.file?(target_file)).to eq true
- end
+ # it 'raises ConversionFailedError when URL cannot be loaded' do
+ # stub_request(:get, url)
+ # expect do
+ # converter = Libreconv::Converter.new(url, target_path)
+ # converter.convert
+ # end.to raise_error(
+ # Libreconv::ConversionFailedError,
+ # /Conversion failed/
+ # )
+ # end
end
- describe "#soffice_command" do
- it "should return the user specified command path" do
- cmd = file_path("soffice") # just faking that the command is present here
- converter = Libreconv::Converter.new(@doc_file, "/target", cmd)
+ describe '#soffice_command' do
+ it 'returns the user specified command path' do
+ # Just faking that the command is present here
+ cmd = fixture_path('soffice')
+ converter = Libreconv::Converter.new(doc_file, '/target', cmd)
expect(converter.soffice_command).to eq cmd
end
- it "should return the command found in path" do
+ it 'returns the command found in path' do
cmd = `which soffice`.strip
- converter = Libreconv::Converter.new(@doc_file, "/target")
+ converter = Libreconv::Converter.new(doc_file, '/target')
expect(converter.soffice_command).to eq cmd
end
end
+ end
- describe ".convert" do
- it "should convert a file to pdf" do
- target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
- Libreconv.convert(@doc_file, @target_path)
- expect(File.file?(target_file)).to eq true
- end
+ describe '#convert' do
+ it 'converts a file to pdf' do
+ target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
+ described_class.convert(doc_file, target_path)
+ expect(File.file?(target_file)).to eq true
end
end
end