test/test_roo.rb in roo-1.3.9 vs test/test_roo.rb in roo-1.3.11

- old
+ new

@@ -156,10 +156,20 @@ yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx) yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice) yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google) end + def with_public_google_spreadsheet(&block) + user = ENV['GOOGLE_MAIL'] + pass = ENV['GOOGLE_PASSWORD'] + ENV['GOOGLE_MAIL'] = '' + ENV['GOOGLE_PASSWORD'] = '' + block.call + ENV['GOOGLE_MAIL'] = user + ENV['GOOGLE_PASSWORD'] = pass + end + # Using Date.strptime so check that it's using the method # with the value set in date_format def test_date with_each_spreadsheet(:name=>'numbers1', :format=>:google) do |oo| # should default to DDMMYYYY @@ -383,11 +393,11 @@ end def test_empty_eh with_each_spreadsheet(:name=>'numbers1') do |oo| assert oo.empty?('a',14) - assert ! oo.empty?('a',15) + assert !oo.empty?('a',15) assert oo.empty?('a',20) end end def test_reload @@ -1197,10 +1207,11 @@ end end def test_write_google # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB + with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo| oo.set_value(1,1,"hello from the tests") assert_equal "hello from the tests", oo.cell(1,1) oo.set_value(1,1, 1.0) assert_equal 1.0, oo.cell(1,1) @@ -1343,11 +1354,11 @@ end end def test_no_remaining_tmp_files_google if GOOGLE - assert_nothing_raised() { + assert_raise(GoogleReadError) { oo = Google.new(key_of("no_spreadsheet_file.txt")) } a=Dir.glob("oo_*") assert_equal [], a end @@ -1778,7 +1789,34 @@ assert_equal Date.new(2009,06,15), oo.cell(1,1) assert_equal Date.new(2009,06,28), oo.cell(2,1) #formula for TODAY(), last calculated on 06.28 assert_equal :date, oo.celltype(1,1) end end + + + def test_bad_excel_date + with_each_spreadsheet(:name=>'bad_exceL_date', :format=>:excel) do |oo| + assert_nothing_raised(ArgumentError) { + assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1) + } + end + end + + def test_public_google_doc + with_public_google_spreadsheet do + assert_raise(GoogleHTTPError) { Google.new("foo") } + assert_raise(GoogleReadError) { Google.new(key_of('numbers1'))} + assert_nothing_raised { Google.new("0AncOJVyN5MMMcjZtN0hGbFVPd3N0MFJUVVR1aFEwT3c") } # use spreadsheet key (private) + assert_nothing_raised { Google.new(key_of('write.me')) } # use spreadsheet key (public) + end + end + + def test_public_google_doc_write + with_public_google_spreadsheet do + assert_raise(GoogleWriteError) { + oo = Google.new(key_of('write.me')) + oo.set_value(1,1,'test') + } + end + end end # class