我对Ruby很新,但过去两周我一直在做大量的厨师测试研究。这个测试使用了Fauxhai的ChefSpec &,但它看起来并不是很“红宝石”,我希望社区能够给我一些关于编码风格的指导。有没有更好的方式来编写这样的嵌套循环?关于Ruby/ChefSpec编码风格的反馈
食谱/富/食谱/ default.rb
package "foo" do
action :install
end
食谱/富/规格/ 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
任何和所有的反馈是值得欢迎的。谢谢!
https://github.com/bbatsov/ruby-style-guide是建议的Ruby编码指南的一个很好的一般资源。我认为在保持可读性的同时清理这些嵌套循环并不是很多。 – 2013-03-05 13:58:42
我已阅读指南,但我看不出有太多的改进。感谢您的反馈! – Rapsey 2013-03-06 08:53:00