我对 Ruby 比较陌生,但在过去的两周里,我一直在对 Chef 测试进行大量研究。这个测试使用 ChefSpec 和 Fauxhai,但它看起来不是很“红宝石”,我希望社区能给我一些关于编码风格的建议。有没有更好的方法来编写这样的嵌套循环?
食谱/foo/recipes/default.rb
package "foo" do
action :install
end
食谱/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
欢迎任何和所有反馈。谢谢!