Cleanup and tests of yaml method

This commit is contained in:
Andy Meneely
2017-04-15 21:25:34 -04:00
parent d53fbc1715
commit f140ff32fa
8 changed files with 147 additions and 8 deletions
+40
View File
@@ -169,4 +169,44 @@ describe Squib::Deck do
end
end
context '#yaml' do
it 'loads basic data' do
expect(Squib.yaml(file: yaml_file('basic.yml')).to_h).to eq({
'Name' => %w(Larry Curly Mo),
'Number' => [4.0, 5.0, 6.0], # numbers get auto-converted to integers
})
end
it 'explodes quantities' do
expect(Squib.yaml(explode: 'qty', file: yaml_file('qty.yml')).to_h).to eq({
'name' => %w(ha ha he),
'qty' => [2, 2, 1],
})
end
it 'handles silence' do
expect(Squib.yaml(file: yaml_file('nilly.yml')).to_h).to eq({
'name' => %w(foo bar),
'desc' => [nil, 'Hello'],
})
end
it 'yields to block when given' do
data = Squib.yaml(file: yaml_file('basic.yml')) do |header, value|
case header
when 'Name'
'he'
when 'Number'
value * 2
else
'ha'
end
end
expect(data.to_h).to eq({
'Name' => %w(he he he),
'Number' => [8.0, 10.0, 12.0],
})
end
end
end
+6
View File
@@ -0,0 +1,6 @@
- Name: Larry
Number: 4.0
- Name: Curly
Number: 5.0
- Name: Mo
Number: 6.0
+3
View File
@@ -0,0 +1,3 @@
- name: foo
- name: bar
desc: Hello
+4
View File
@@ -0,0 +1,4 @@
- name: ha
qty: 2
- name: he
qty: 1
+4
View File
@@ -46,6 +46,10 @@ def xlsx_file(file)
"#{File.expand_path(File.dirname(__FILE__))}/data/xlsx/#{file}"
end
def yaml_file(file)
"#{File.expand_path(File.dirname(__FILE__))}/data/yaml/#{file}"
end
def project_template(file)
"#{File.expand_path(File.dirname(__FILE__))}/../lib/squib/project_template/#{file}"
end