test/test_roo.rb in roo-2.0.0 vs test/test_roo.rb in roo-2.0.1

- old
+ new

@@ -16,10 +16,11 @@ # Dump warnings that come from the test to open files # with the wrong spreadsheet class #STDERR.reopen "/dev/null","w" require 'test_helper' +require 'stringio' class TestRoo < Minitest::Test OPENOFFICE = true # do OpenOffice-Spreadsheet Tests? (.ods files) EXCELX = true # do Excelx Tests? (.xlsx files) @@ -61,11 +62,11 @@ formats.each do |format| begin yield Roo::Spreadsheet.open(File.join(TESTDIR, fixture_filename(options[:name], format))) rescue => e - raise e, "#{e.message} for #{format}", e.backtrace + raise e, "#{e.message} for #{format}", e.backtrace unless options[:ignore_errors] end end end def test_sheets_csv @@ -2061,7 +2062,27 @@ end end end end + def test_open_stream + return unless EXCELX + file_contents = File.read File.join(TESTDIR, fixture_filename(:numbers1, :excelx)) + stream = StringIO.new(file_contents) + xlsx = Roo::Excelx.new(stream) + assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], xlsx.sheets + end + def test_close + with_each_spreadsheet(:name=>'numbers1') do |oo| + next unless (tempdir = oo.instance_variable_get('@tmpdir')) + oo.close + assert !File.exists?(tempdir), "Expected #{tempdir} to be cleaned up, but it still exists" + end + end + + def test_cleanup_on_error + old_temp_files = Dir.open(Dir.tmpdir).to_a + with_each_spreadsheet(:name=>'non_existent_file', :ignore_errors=>true) do |oo|; end + assert_equal Dir.open(Dir.tmpdir).to_a, old_temp_files + end end # class