Sha256: caba1bd638e80e8d24f5a9e7b6e80fb92e0023ee46134ef73fc0feb11091e161

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require "esv"

describe ESV, ".generate and .parse" do
  it "works" do
    data = ESV.generate do |esv|
      esv << [ "Dogs", "Cats" ]
      esv << [ 1, 2 ]
    end

    output = ESV.parse(data)

    expect(output).to eq [
      [ "Dogs", "Cats" ],
      [ 1, 2 ],
    ]
  end
end

describe ESV, ".parse" do
  it "raises if there's more than one worksheet" do
    expect {
      ESV.parse(excel_file_with_two_worksheets)
    }.to raise_error(/Expected 1 worksheet, found 2/)
  end

  private

  def excel_file_with_two_worksheets
    book = Spreadsheet::Workbook.new
    book.create_worksheet
    book.create_worksheet

    data = ""
    fake_file = StringIO.new(data)
    book.write(fake_file)
    data
  end
end

describe ESV, ".generate_file and .parse_file" do
  before do
    @file = Tempfile.new("esv")
  end

  it "works" do
    path = @file.path

    ESV.generate_file(path) do |esv|
      esv << [ "Dogs", "Cats" ]
      esv << [ 1, 2 ]
    end

    output = ESV.parse_file(path)

    expect(output).to eq [
      [ "Dogs", "Cats" ],
      [ 1, 2 ],
    ]
  end

  after do
    @file.close
    @file.unlink
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
excel-esv-1.0.0 spec/esv_spec.rb
excel-esv-0.0.7 spec/esv_spec.rb
excel-esv-0.0.6 spec/esv_spec.rb