Sha256: b2c4f57d1c5b99ec0f9c94d9b3b9087e2628813fa7fa8f72dc9f893d9c02939b

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

require 'test_helper'
require 'ndr_import/file/docx'

module NdrImport
  module File
    # Word .docx document file handler tests
    class DocxTest < ActiveSupport::TestCase
      def setup
        @permanent_test_files = SafePath.new('permanent_test_files')
      end

      test 'should read word file' do
        file_path = @permanent_test_files.join('hello_world.docx')
        handler = NdrImport::File::Docx.new(file_path, nil)
        handler.tables.each do |tablename, sheet|
          assert_nil tablename
          assert_instance_of Enumerator, sheet
          assert_equal [
            'Hello world, this is a modern word document',
            'With more than one line of text',
            'Three in fact'
          ], sheet.to_a
        end
      end

      test 'should raise exception on invalid word file' do
        assert_raises RuntimeError do
          file_path = @permanent_test_files.join('not_a_word_file.docx')
          handler = NdrImport::File::Docx.new(file_path, nil)
          handler.tables.each do |tablename, sheet|
            assert_nil tablename
            assert_instance_of Enumerator, sheet
            sheet.to_a
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ndr_import-8.4.0 test/file/docx_test.rb
ndr_import-8.3.0 test/file/docx_test.rb
ndr_import-8.2.0 test/file/docx_test.rb
ndr_import-8.1.0 test/file/docx_test.rb
ndr_import-8.0.0 test/file/docx_test.rb
ndr_import-7.0.0 test/file/docx_test.rb
ndr_import-6.4.1 test/file/docx_test.rb
ndr_import-6.4.0 test/file/docx_test.rb
ndr_import-6.3.0 test/file/docx_test.rb
ndr_import-6.2.0 test/file/docx_test.rb