Sha256: 8882d65fe55ffc83b6862cb558680445b6f4b0381cc7df6c96662d0c5b88c004

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require 'spec_helper'
using ClassExtensions if RUBY_VERSION > '2.1'

describe Rspreadsheet do
  before do
    @tmp_filename = '/tmp/testfile.ods'        
    File.delete(@tmp_filename) if File.exists?(@tmp_filename)  # delete temp file
  end
  
  
  it 'can open spreadsheet and save it to file, resulting file has same content as original' do
    spreadsheet = Rspreadsheet.new($test_filename)                 # open a file
    spreadsheet.save(@tmp_filename)                                # and save spreadsheet as temp file
    
    # now compare content saved file to original
    contents_of_files_are_identical?($test_filename,@tmp_filename).should == true
  end
  
  it 'can open spreadsheet and store it to IO object', :pending => 'Under development' do
    spreadsheet = Rspreadsheet.new($test_filename)                 # open a file
    
    stringio = StringIO.new
    spreadsheet.save_to_io(stringio)
    stringio.size.should > 300000
    
    # save it to temp file
    File.open(@tmp_filename, "w") do |f|
      f.write stringio.read                                  
    end
     
    contents_of_files_are_identical?($test_filename,@tmp_filename).should == true
  end
end

def contents_of_files_are_identical?(filename1,filename2)
  @content_xml1 = Zip::File.open(filename1) do |zip|
    LibXML::XML::Document.io zip.get_input_stream('content.xml')
  end
  @content_xml2 = Zip::File.open(filename2) do |zip|
    LibXML::XML::Document.io zip.get_input_stream('content.xml')
  end
  return contents_are_identical?(@content_xml1,@content_xml2)
end

def contents_are_identical?(content_xml1,content_xml2)
  content_xml2.root.first_diff(content_xml1.root).should be_nil
  content_xml1.root.first_diff(content_xml2.root).should be_nil
  
  return (content_xml1.root == content_xml2.root)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspreadsheet-0.3 spec/io_spec.rb