@@ -20,22 +20,31 @@ describe Squib::Deck do
|
||||
})
|
||||
end
|
||||
|
||||
it 'handles spaces properly' do
|
||||
it 'strips spaces by default' do
|
||||
expect(Squib.csv(file: csv_file('with_spaces.csv'))).to eq({
|
||||
'With Spaces' => ['a b c ', 3],
|
||||
'With Spaces' => ['a b c', 3],
|
||||
'h2' => [2, 4],
|
||||
'h3' => [3, nil]
|
||||
})
|
||||
end
|
||||
|
||||
it 'skips space stripping if told to' do
|
||||
expect(Squib.csv(strip: false, file: csv_file('with_spaces.csv'))).to eq({
|
||||
' With Spaces ' => ['a b c ', 3],
|
||||
'h2' => [2, 4],
|
||||
'h3' => [3, nil]
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '#xlsx' do
|
||||
it 'loads basic xlsx data' do
|
||||
expect(Squib.xlsx(file: xlsx_file('basic.xlsx'))).to eq({
|
||||
'Name' => %w(Larry Curly Mo),
|
||||
'General Number' => %w(1 2 3), #general types always get loaded as strings with no conversion
|
||||
'Actual Number' => [4.0, 5.0, 6.0], #numbers get auto-converted to integers
|
||||
})
|
||||
'Name' => %w(Larry Curly Mo),
|
||||
'General Number' => %w(1 2 3), #general types always get loaded as strings with no conversion
|
||||
'Actual Number' => [4.0, 5.0, 6.0], #numbers get auto-converted to integers
|
||||
})
|
||||
end
|
||||
|
||||
it 'loads xlsx with formulas' do
|
||||
@@ -53,5 +62,35 @@ describe Squib::Deck do
|
||||
})
|
||||
end
|
||||
|
||||
it 'strips whitespace by default' do
|
||||
expect(Squib.xlsx(file: xlsx_file('whitespace.xlsx'))).to eq({
|
||||
'With Whitespace' => ['foo', 'bar', 'baz'],
|
||||
})
|
||||
end
|
||||
|
||||
it 'does not strip whitespace when specified' do
|
||||
expect(Squib.xlsx(file: xlsx_file('whitespace.xlsx'), strip: false)).to eq({
|
||||
' With Whitespace ' => ['foo ', ' bar', ' baz '],
|
||||
})
|
||||
end
|
||||
|
||||
it 'yields to block when given' do
|
||||
data = Squib.xlsx(file: xlsx_file('basic.xlsx')) do |header, value|
|
||||
case header
|
||||
when 'Name'
|
||||
'he'
|
||||
when 'Actual Number'
|
||||
value * 2
|
||||
else
|
||||
'ha'
|
||||
end
|
||||
end
|
||||
expect(data).to eq({
|
||||
'Name' => %w(he he he),
|
||||
'General Number' => %w(ha ha ha),
|
||||
'Actual Number' => [8.0, 10.0, 12.0],
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user