spec/libreconv_spec.rb in libreconv-0.6.1 vs spec/libreconv_spec.rb in libreconv-0.7.0
- old
+ new
@@ -1,24 +1,41 @@
# encoding: utf-8
-
require 'spec_helper'
+require 'webrick'
+
+include WEBrick
describe Libreconv do
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")
- @bin_file = file_path("bin.bin")
@target_path = "/tmp/libreconv"
+
+ dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
+ port = 50506
+ @url = "http://#{Socket.gethostname}:#{port}"
+ @t1 = Thread.new do
+ @server = HTTPServer.new(:Port => port, :DocumentRoot => dir, :AccessLog => [], :Logger => WEBrick::Log::new("/dev/null", 7))
+ @server.start
+ end
end
- after(:all) do
+ before(:each) do
+ FileUtils.mkdir_p @target_path
+ end
+
+ after(:each) do
FileUtils.rm_rf @target_path
end
+ after(:all) do
+ @t1.exit
+ end
+
describe Libreconv::Converter do
describe "#new" do
it "should raise error if soffice command does not exists" do
lambda { Libreconv::Converter.new(@doc_file, "/target", "/Whatever/soffice") }.should raise_error(IOError)
end
@@ -27,53 +44,52 @@
lambda { Libreconv::Converter.new(file_path("nonsense.txt"), "/target") }.should 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)
+ converter.convert
+ File.file?(target_file).should == 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)
converter.convert
- File.exists?(target_file).should == true
+ File.file?(target_file).should == 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)
converter.convert
- File.exists?(target_file).should == true
+ File.file?(target_file).should == 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)
converter.convert
- File.exists?(target_file).should == true
+ File.file?(target_file).should == 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)
converter.convert
- File.exists?(target_file).should == true
+ File.file?(target_file).should == true
end
it "should convert a docx to pdf specifying an URL as source" do
- url = "https://www.filepicker.io/api/file/XqCEPkH9RdOQr0S6zF5N"
- target_file = "#{@target_path}/XqCEPkH9RdOQr0S6zF5N.pdf"
+ url = "#{@url}/docx.docx"
+ target_file = "#{@target_path}/docx.pdf"
converter = Libreconv::Converter.new(url, @target_path)
converter.convert
- File.exists?(target_file).should == true
+ File.file?(target_file).should == true
end
-
- it "try converting binary file" do
- source = @bin_file
- target_file = "#{@target_path}/#{File.basename(source, ".bin")}.pdf"
- converter = Libreconv::Converter.new(source, @target_path)
- converter.convert
- File.exists?(target_file).should == false
- 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
@@ -90,10 +106,10 @@
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)
- File.exists?(target_file).should == true
+ File.file?(target_file).should == true
end
end
end
end
\ No newline at end of file