spec/esv_spec.rb in excel-esv-2.0.0 vs spec/esv_spec.rb in excel-esv-3.0.0
- old
+ new
@@ -21,36 +21,80 @@
expect {
ESV.parse(excel_file_with_two_worksheets)
}.to raise_error(/Expected 1 worksheet, found 2/)
end
- it "ignores formatting" do
+ it "ignores formatting, always returning a plain array of data" do
output = ESV.parse(excel_file_with_formatting([1, 2]))
expect(output).to eq [
[ 1, 2 ],
]
expect(output[0].class).to eq Array
end
+ it "returns the last value of a formula cell" do
+ output = ESV.parse(excel_file_with_formula)
+ expect(output).to eq [
+ [ "one", "two" ],
+ ]
+
+ expect(output[0].class).to eq Array
+ end
+
+ it "returns the last value of a formula cell" do
+ output = ESV.parse(excel_file_with_formula)
+ expect(output).to eq [
+ [ "one", "two" ],
+ ]
+
+ expect(output[0].class).to eq Array
+ end
+
+ it "returns the URL of a link cell" do
+ output = ESV.parse(excel_file_with_link("https://example.com"))
+ expect(output).to eq [
+ [ "one", "https://example.com" ],
+ ]
+
+ expect(output[0][1].class).to eq String
+ 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
+ excel_file do |sheet, book|
+ book.create_worksheet
+ end
end
def excel_file_with_formatting(data)
+ excel_file do |sheet|
+ sheet.row(0).replace(data)
+ sheet.row(0).default_format = Spreadsheet::Format.new(color: :blue)
+ end
+ end
+
+ def excel_file_with_formula
+ excel_file do |sheet|
+ formula = Spreadsheet::Formula.new
+ formula.value = "two"
+ sheet.row(0).replace([ "one", formula ])
+ end
+ end
+
+ def excel_file_with_link(url)
+ excel_file do |sheet|
+ link = Spreadsheet::Link.new(url)
+ sheet.row(0).replace([ "one", link ])
+ end
+ end
+
+ def excel_file(&block)
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
- sheet.row(0).replace(data)
- sheet.row(0).default_format = Spreadsheet::Format.new(color: :blue)
+
+ block.call(sheet, book)
data = ""
fake_file = StringIO.new(data)
book.write(fake_file)
data