test/test_generic_spreadsheet.rb in roo-1.13.2 vs test/test_generic_spreadsheet.rb in roo-2.0.0beta1

- old
+ new

@@ -1,9 +1,9 @@ # -*- encoding: utf-8 -*- require File.dirname(__FILE__) + '/test_helper' -class TestBase < Test::Unit::TestCase +class TestBase < Minitest::Test def setup @klass = Class.new(Roo::Base) do def initialize(filename='some_file') super @@ -13,16 +13,16 @@ def read_cells(sheet=nil) @cells_read[sheet] = true end def cell(row, col, sheet=nil) - sheet ||= @default_sheet + sheet ||= default_sheet @cell[sheet][[row,col]] end def celltype(row, col, sheet=nil) - sheet ||= @default_sheet + sheet ||= default_sheet @cell_type[sheet][[row,col]] end def sheets ['my_sheet','blank sheet'] @@ -30,83 +30,28 @@ end @oo = @klass.new setup_test_sheet(@oo) end - context 'Roo::Base.letter_to_number(letter)' do - should "give us 1 for 'A' and 'a'" do - assert_equal 1, Roo::Base.letter_to_number('A') - assert_equal 1, Roo::Base.letter_to_number('a') + context 'private method Roo::Base.uri?(filename)' do + should "return true when passed a filename starts with http(s)://" do + assert_equal true, @oo.send(:uri?, 'http://example.com/') + assert_equal true, @oo.send(:uri?, 'https://example.com/') end - should "give us the correct value for 'Z'" do - assert_equal 26, Roo::Base.letter_to_number('Z') + should "return false when passed a filename which does not start with http(s)://" do + assert_equal false, @oo.send(:uri?, 'example.com') end - should "give us the correct value for 'AA' regardless of case mixing" do - assert_equal 27, Roo::Base.letter_to_number('AA') - assert_equal 27, Roo::Base.letter_to_number('aA') - assert_equal 27, Roo::Base.letter_to_number('Aa') - assert_equal 27, Roo::Base.letter_to_number('aa') + should "return false when passed non-String object such as Tempfile" do + assert_equal false, @oo.send(:uri?, Tempfile.new('test')) end - - should "give us the correct value for 'AB'" do - assert_equal 28, Roo::Base.letter_to_number('AB') - end - - should "give us the correct value for 'AZ'" do - assert_equal 26*2, Roo::Base.letter_to_number('AZ') - end - - should "give us the correct value for 'BZ'" do - assert_equal 26*3, Roo::Base.letter_to_number('BZ') - end - - should "give us the correct value for 'ZZ'" do - assert_equal 26**2 + 26,Roo::Base.letter_to_number('ZZ') - end end - context "Roo::Base.number_to_letter" do - Roo::Base::LETTERS.each_with_index do |l,i| - should "return '#{l}' when passed #{i+1}" do - assert_equal l,Roo::Base.number_to_letter(i+1) - end - end - - should "return 'AA' when passed 27" do - assert_equal 'AA',Roo::Base.number_to_letter(27) - end - - should "return 'AZ' when passed #{26*2}" do - assert_equal 'AZ', Roo::Base.number_to_letter(26*2) - end - - should "return 'BZ' when passed #{26*3}" do - assert_equal 'BZ', Roo::Base.number_to_letter(26*3) - end - - should "return 'ZZ' when passed #{26**2 + 26}" do - assert_equal 'ZZ',Roo::Base.number_to_letter(26**2 + 26) - end - - should "return 'AAA' when passed #{26**2 + 27}" do - assert_equal 'AAA',Roo::Base.number_to_letter(26**2 + 27) - end - - should "return 'ZZZ' when passed #{26**3 + 26**2 + 26}" do - assert_equal 'ZZZ',Roo::Base.number_to_letter(26**3 + 26**2 + 26) - end - - should "return the correct letter when passed a Float" do - assert_equal 'A',Roo::Base.number_to_letter(1.0) - end - end - def test_setting_invalid_type_does_not_update_cell @oo.set(1,1,1) - assert_raise(ArgumentError){@oo.set(1,1, :invalid_type)} + assert_raises(ArgumentError){@oo.set(1,1, :invalid_type)} assert_equal 1, @oo.cell(1,1) assert_equal :float, @oo.celltype(1,1) end def test_first_row @@ -172,10 +117,14 @@ end def test_to_csv assert_equal expected_csv,@oo.to_csv end + + def test_to_csv_with_separator + assert_equal expected_csv_with_semicolons,@oo.to_csv(nil, ';') + end protected def setup_test_sheet(workbook=nil) workbook ||= @oo set_sheet_values(workbook) set_sheet_types(workbook) @@ -253,7 +202,10 @@ read_hash[workbook.default_sheet] = true end def expected_csv ",,,,,,\n,,,,,,\n,,,,,,\n,,,,,,\n1961-11-21,,,,,,\n,,,,,,\n,,,,,,\n,,\"thisisc8\",,,,\"thisisg8\"\n,,,,,,\n,,,,,,\n,,,,,,\n41,42,43,44,45,,\n,,,,,,\n,,,,,,\n,,43,44,45,,\n,,\"dreiundvierzig\",\"vierundvierzig\",\"fuenfundvierzig\",,\n" + end + def expected_csv_with_semicolons + expected_csv.gsub /\,/, ';' end end