我有以下rspec ruby代码。我正在测试一些人偶模块。它引发了掉毛错误。
Block body expression is on the same line as the block start. (convention:Layout/MultilineBlockLayout)
describe "on #{os}" do
let(:facts) { facts }
it { is_expected.to contain_class('windows_some_thing::some_suite') }
context 'with some_suite_enabled' do
let(:params) { { cipher_suite: %w[ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521 ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521 ] } }
it { is_expected.to contain_registry_value('HKLM\SOFTWARE\Policies\Microsoft\something\something\something\000000\Functions').with(
ensure: 'present',
type: 'string',
data: 'ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521,ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521 ',
)
}
end
我可以使用rubocop -a
修复它。但是,这将按照以下方式更正代码。然后得到一个不同的棉绒错误
Name your test subject if you need to reference it explicitly. (convention:RSpec/NamedSubject)
it {
expect(subject).to contain_registry_value('HKLM\SOFTWARE\Policies\Microsoft\something\something\something\000000\Functions').with(
ensure: 'present',
type: 'string',
data: 'ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521,ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521 ',
)
}
如何为ruby-2.4-strict
修复此问题?我有超过10000个需要修复的掉毛错误。分布在多个文件和模块中。因此,我需要一个实用的直接解决方案。我知道这将非常耗时。但是我不希望它花一年的时间来做。
更简单,更直接的更正
Block body expression is on the same line as the block start. (convention:Layout/MultilineBlockLayout)
将涉及此:
it {
is_expected.to contain_registry_value('HKLM\SOFTWARE\Policies\Microsoft\something\something\something\000000\Functions').with(
ensure: 'present',
type: 'string',
data: 'ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521,ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521 ',
)
}
规则是,multiline块的开始和结束定界符必须出现在与块主体中任何内容(空格除外)分开的行上。
同样,它仍然会升起一个标志,但是其纠正更明显。短绒棉布希望您使用do
和end
来分隔多行块,因此这是您最终想要的位置:
it do
is_expected.to contain_registry_value('HKLM\SOFTWARE\Policies\Microsoft\something\something\something\000000\Functions').with(
ensure: 'present',
type: 'string',
data: 'ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521,ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521 ',
)
end
甚至在这里:
it do
is_expected.to contain_registry_value('HKLM\SOFTWARE\Policies\Microsoft\something\something\something\000000\Functions')
.with(
ensure: 'present',
type: 'string',
data: 'ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521,ABC_ECDHE_JKL_WITH_ABC_123_RET_ABC_384_521 ',
)
end
我发现这最后一个更具可读性,特别是如果您要链接其他谓词。