spec/dullard_spec.rb in dullard-0.1.0 vs spec/dullard_spec.rb in dullard-0.2.0
- old
+ new
@@ -1,8 +1,8 @@
require 'dullard'
-describe "dullard," do
+describe "test.xlsx," do
before(:each) do
@file = File.open(File.expand_path("../test.xlsx", __FILE__))
end
describe "when it has no user defined formats," do
@@ -20,11 +20,10 @@
it "reads the right number of columns, even with blanks" do
rows = @xlsx.sheets[0].rows
rows.next.count.should == 300
rows.next.count.should == 9
- rows.next.count.should == 1
end
it "reads the right number of rows" do
@xlsx.sheets[0].row_count.should == 117
end
@@ -67,7 +66,51 @@
row[4].strftime("%Y-%m-%d %H:%M:%S").should == "2012-07-01 21:18:52"
end
end
count.should == 117
end
+ end
+end
+
+describe "test2.xlsx" do
+ before(:each) do
+ @file = File.open(File.expand_path("../test2.xlsx", __FILE__))
+ end
+
+ it "should not skip nils" do
+ rows = Dullard::Workbook.new(@file).sheets[0].rows.to_a
+ rows.should == [
+ [1],
+ [nil, 2],
+ [nil, nil, 3]
+ ]
+ end
+end
+
+describe "error handling" do
+ it "should raise an error when a cell is missing r attr" do
+ @file = File.expand_path("../error_missing_r.xlsx", __FILE__)
+ book = Dullard::Workbook.new(@file)
+ sheet = book.sheets[0]
+ expect {
+ sheet.rows.to_a
+ }.to raise_error(Dullard::Error)
+ end
+
+ it "should succeed when styles are missing" do
+ file = File.expand_path("../error_missing_metadata.xlsx", __FILE__)
+ book = Dullard::Workbook.new(file)
+ sheet = book.sheets[0]
+ expect {
+ sheet.rows.to_a
+ }.not_to raise_error
+ end
+
+ it "should raise an error with invalid shared string index" do
+ file = File.expand_path("../error_missing_ss.xlsx", __FILE__)
+ book = Dullard::Workbook.new(file)
+ sheet = book.sheets[0]
+ expect {
+ sheet.rows.to_a
+ }.to raise_error(Dullard::Error)
end
end