spec/esv_spec.rb in excel-esv-3.0.0 vs spec/esv_spec.rb in excel-esv-3.0.1

- old
+ new

@@ -1,8 +1,8 @@ require "esv" -describe ESV, ".generate and .parse" do +RSpec.describe ESV, ".generate and .parse" do it "works" do data = ESV.generate do |esv| esv << [ "Dogs", "Cats" ] esv << [ 1, 2 ] end @@ -14,84 +14,68 @@ [ 1, 2 ], ] end end -describe ESV, ".parse" do +RSpec.describe ESV, ".parse" do it "raises if there's more than one worksheet" do + excel_file_with_two_worksheets = generate_excel_file do |sheet, book| + book.create_worksheet + end + expect { ESV.parse(excel_file_with_two_worksheets) }.to raise_error(/Expected 1 worksheet, found 2/) end 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 ], - ] + excel_file_with_formatting = generate_excel_file do |sheet| + sheet.row(0).replace([ 1, 2 ]) + sheet.row(0).default_format = Spreadsheet::Format.new(color: :blue) + end - expect(output[0].class).to eq Array - end + output = ESV.parse(excel_file_with_formatting) - it "returns the last value of a formula cell" do - output = ESV.parse(excel_file_with_formula) expect(output).to eq [ - [ "one", "two" ], + [ 1, 2 ], ] expect(output[0].class).to eq Array end it "returns the last value of a formula cell" do + excel_file_with_formula = generate_excel_file do |sheet| + formula = Spreadsheet::Formula.new + formula.value = "two" + sheet.row(0).replace([ "one", formula ]) + end + 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")) + excel_file_with_link = generate_excel_file do |sheet| + link = Spreadsheet::Link.new("https://example.com", "desc", "foo") + sheet.row(0).replace([ "one", link ]) + end + output = ESV.parse(excel_file_with_link) expect(output).to eq [ - [ "one", "https://example.com" ], + [ "one", "https://example.com#foo" ], ] expect(output[0][1].class).to eq String end private - def excel_file_with_two_worksheets - 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) + def generate_excel_file(&block) book = Spreadsheet::Workbook.new sheet = book.create_worksheet block.call(sheet, book) @@ -100,10 +84,10 @@ book.write(fake_file) data end end -describe ESV, ".generate_file and .parse_file" do +RSpec.describe ESV, ".generate_file and .parse_file" do before do @file = Tempfile.new("esv") end it "works" do