rubocop rspec ruby2.4-限制规则MultilineBlockLayout和NamedSubject冲



我有以下rspec ruby代码。我正在测试一些木偶模块。它抛出了一个linting错误。

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('HKLMSOFTWAREPoliciesMicrosoftsomethingsomethingsomething00000Functions').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('HKLMSOFTWAREPoliciesMicrosoftsomethingsomethingsomething00000Functions').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('HKLMSOFTWAREPoliciesMicrosoftsomethingsomethingsomething00000Functions').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 ',
)
}

规则是多行块的开始和结束分隔符必须与块体中的任何内容(空白除外(分别出现在不同的行上。

同样,这也将引发一个信号,但其修正更为明显。linter希望您使用doend来定义多行块,因此这就是您最终想要的位置:

it do
is_expected.to contain_registry_value('HKLMSOFTWAREPoliciesMicrosoftsomethingsomethingsomething00000Functions').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('HKLMSOFTWAREPoliciesMicrosoftsomethingsomethingsomething00000Functions')
.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

我发现这最后一个更可读,特别是如果您想链接其他谓词的话。

相关内容

  • 没有找到相关文章

最新更新