I'm rather new to Ruby, but I have been doing a lot of research on Chef testing for the past two weeks. This test uses ChefSpec & Fauxhai, but it doesn't look very "ruby-ish" and I was hoping the community could give me some pointers on coding style. Is there a better way to write a nested loop like this?
cookbooks/foo/recipes/default.rb
package "foo" do
action :install
end
cookbooks/foo/spec/default_spec.rb
require 'chefspec'
describe 'foo::default' do
platforms = {
"debian" => ['6.0.5'],
"ubuntu" => ['12.04', '10.04'],
"centos" => ['5.8', '6.0', '6.3'],
"redhat" => ['5.8', '6.3'],
"mac_os_x" => ['10.6.8', '10.7.4', '10.8.2'],
"windows" => ['2008R2']
}
platforms.each do |platform,versions|
versions.each do |version|
context "on #{platform} #{version}" do
before do
Fauxhai.mock(platform: platform, version: version)
end
it 'should install foo' do
@runner = ChefSpec::ChefRunner.new.converge('foo::default')
@runner.should install_package 'foo'
end
end
end
end
end
Any and all feedback is welcome. Thank you!