Sha256: 39a5eb89633f060772c64c0a5c16f77d4a14d24bf0cf81532c03cd50970a9529
Contents?: true
Size: 1.92 KB
Versions: 5
Compression:
Stored size: 1.92 KB
Contents
require 'helper' # Generate tests for converting to and from various formats. Use two nested # loops to iterate over each source and destination format, using files with # names of the following structure: "format.#{format_name}" describe 'Conversions' do @extensions = [] Dir.glob(File.join(File.dirname(__FILE__), 'files', 'format*')) do |f| @extensions << f.match(/format\.(\w+)\Z/)[1] end [:markdown, :html, :rst, :latex].each do |from| @extensions.each do |to| next if from == to it "converts #{from} to #{to}" do files_dir = File.join(File.dirname(__FILE__), 'files') from_content = File.read(File.join(files_dir, "format.#{from}")) to_content = File.read(File.join(files_dir, "format.#{to}")) converted_content = PandocRuby.convert( from_content, :from => from, :to => to ) assert_equal(converted_content.strip, to_content.strip) end end end describe '.docx' do it "converts from docx to html" do converted_content = PandocRuby.convert( ['./test/files/reference.docx'], :from => 'docx', :to => 'html' ) assert_equal("<p>Hello World.</p>", converted_content.strip) end it "raises an error when attempting to convert doc with docx format" do error = assert_raises(RuntimeError) do PandocRuby.convert( ['./test/files/reference.doc'], :from => 'docx', :to => 'html' ) end assert_match(/couldn't parse docx file/, error.message) end it "raises an error when attempting to convert doc with doc format" do error = assert_raises(RuntimeError) do PandocRuby.convert( ['./test/files/reference.doc'], :from => 'doc', :to => 'html' ) end assert_match(/Pandoc can convert from DOCX, but not from DOC./, error.message) end end end
Version data entries
5 entries across 5 versions & 1 rubygems