test/helper.rb in write_xlsx-0.85.5 vs test/helper.rb in write_xlsx-0.85.6

- old
+ new

@@ -11,11 +11,14 @@ require 'test-unit' $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'write_xlsx' +require 'stringio' +require 'tempfile' + class Writexlsx::Workbook # # Set the default index for each format. This is mainly used for testing. # def set_default_xf_indices #:nodoc: @@ -26,12 +29,17 @@ class Test::Unit::TestCase def setup_dir_var @test_dir = File.dirname(__FILE__) @perl_output = File.join(@test_dir, 'perl_output') @regression_output = File.join(@test_dir, 'regression', 'xlsx_files') + @io = StringIO.new end + def expected_xlsx + File.join(@regression_output, @xlsx) + end + def expected_to_array(lines) array = [] lines.each_line do |line| str = line.chomp.sub(/^\s+/, '') array << str unless str == '' @@ -64,9 +72,21 @@ def entrys(xlsx) result = [] Zip::ZipFile.foreach(xlsx) { |entry| result << entry } result + end + + def compare_for_regression(ignore_members = nil, ignore_elements = nil) + store_to_tempfile + compare_xlsx(expected_xlsx, @tempfile.path, ignore_members, ignore_elements, true) + end + + def store_to_tempfile + @tempfile = Tempfile.open(@xlsx) + @tempfile.binmode + @tempfile.write(@io.string) + @tempfile.close end def compare_xlsx_for_regression(exp_filename, got_filename, ignore_members = nil, ignore_elements = nil) compare_xlsx(exp_filename, got_filename, ignore_members, ignore_elements, true) end