• script
#!/usr/bin/env ruby
# coding: utf-8
#
require 'csv'
require 'erb'

def _tmpl
  return ERB.new(<<-EOS, nil, '-')
describe file '<%= name %>' do
  it_behaves_like 'a <%= type %> <%= owner %>:<%= group %> <%= perm %>'
end
  EOS
end
  
def parse(fname)
  CSV.foreach( fname, { :col_sep => ',', :headers => true }) do | row |
    prm = -> {
      type  = row["type" ]
      name  = row["name" ]
      owner = row["owner"]
      group = row["group"]
      perm  = row["perm" ]

      binding
    }   

    erb = _tmpl
    puts erb.result(prm.call())

  end 
end

parse('./flst.csv')


  • flst.csv
$ cat flst.csv 
type,name,owner,group,perm
file,/etc/hosts,root,wheel,644
file,/etc/group,root,wheel,644
directory,/opt,root,wheel,755
  • 結果
describe file '/etc/hosts' do
  it_behaves_like 'a file root:wheel 644'
end
describe file '/etc/group' do
  it_behaves_like 'a file root:wheel 644'
end
describe file '/opt' do
  it_behaves_like 'a directory root:wheel 755'
end