我對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