spec/integration/integration_helper.rb in pdf_ravager-0.1.0 vs spec/integration/integration_helper.rb in pdf_ravager-0.2.0

- old
+ new

@@ -1,14 +1,15 @@ require File.dirname(__FILE__) + '/../spec_helper' -require 'rspec' -require 'pdf_ravager' require 'securerandom' require 'chunky_png' require 'tempfile' def mktemp(ext) - Tempfile.new(['', ext]).path + f = Tempfile.new(['', ext]) + (@@prevent_gc ||= []) << f # prevents file from getting deleted until all tests are done + f.close + f.path end def pdf_to_ps(pdf_file, out_file=nil) out_file ||= mktemp('.ps') system("acroread -toPostScript -markupsOn -pairs #{pdf_file} #{out_file} >/dev/null 2>&1") @@ -21,9 +22,19 @@ out_file end def pdf_to_png(pdf_file) ps_to_png(pdf_to_ps(pdf_file)) +end + +def ravage_to_temp_file(template, input_pdf) + file = mktemp('.pdf') + template.ravage input_pdf, :out_file => file + file +end + +def compare_pdf_to_png(input_pdf, png) + png_diff(pdf_to_png(input_pdf), png) end # code taken from http://jeffkreeftmeijer.com/2011/comparing-images-and-creating-image-diffs/ def png_diff(img1, img2) images = [