Module: Sablon::Test::Assertions
- Defined in:
- lib/sablon/test/assertions.rb
Instance Method Summary collapse
- #assert_docx_equal(expected_path, actual_path) ⇒ Object
-
#diff_docx_files(expected_path, actual_path) ⇒ Object
Returns a hash of all XML files that differ in the docx file.
Instance Method Details
#assert_docx_equal(expected_path, actual_path) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sablon/test/assertions.rb', line 4 def assert_docx_equal(expected_path, actual_path) # # Parse document archives and generate a diff xml_diffs = diff_docx_files(expected_path, actual_path) # # build error message msg = 'The generated document does not match the sample. Please investigate file(s): ' msg += xml_diffs.keys.sort.join(', ') xml_diffs.each do |name, diff_text| msg += "\n#{'-' * 72}\nFile: #{name}\n#{diff_text}\n" end msg += '-' * 72 + "\n" msg += "If the generated document is correct, the sample needs to be updated:\n" msg += "\t cp #{actual_path} #{expected_path}" # raise Minitest::Assertion, msg unless xml_diffs.empty? end |
#diff_docx_files(expected_path, actual_path) ⇒ Object
Returns a hash of all XML files that differ in the docx file. This only checks files that have the extension “.xml” or “.rels”.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sablon/test/assertions.rb', line 25 def diff_docx_files(expected_path, actual_path) expected = parse_docx(expected_path) actual = parse_docx(actual_path) xml_diffs = {} # expected.each do |entry_name, expect| next unless entry_name =~ /.xml$|.rels$/ next unless expect != actual[entry_name] # xml_diffs[entry_name] = diff(expect, actual[entry_name]) end # xml_diffs end |