Skip to content

Instantly share code, notes, and snippets.

@bolshakov
Created March 21, 2018 16:28
Show Gist options
  • Save bolshakov/48a48a34efa48d8c947d90fb1c80fc16 to your computer and use it in GitHub Desktop.
Save bolshakov/48a48a34efa48d8c947d90fb1c80fc16 to your computer and use it in GitHub Desktop.
RSpec::Matchers.define :be_identical_docx_file_to do |expected_docx_file|
match do |actual_docx_file|
expected_file = extract_zip_file(expected_docx_file)
actual_file = extract_zip_file(actual_docx_file)
expected_file == actual_file
end
# @param path [String] path to docx file
# @return [{String => String}] maps file names to file content
private def extract_zip_file(path)
Zip::File.open(path) do |zip_file|
zip_file.each_with_object({}) do |entry, files|
files[entry.name] = entry.get_input_stream.read
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment