Closed backus closed 7 years ago
My initial thought is that, while this is a false positive in that these are not redundant examples like this cop usually detects, it is also tricky to say what should be done here. Here is a solution @alexjfisher could take to make these specs a bit more idiomatic to RSpec and kill the flags here:
Diff:
15,23c15
< it { is_expected.to contain_package('squid3').with_ensure('present') }
< it { is_expected.to contain_service('squid3').with_ensure('running') }
< it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_group('root') }
< it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_owner('root') }
< it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid3/squid.conf') }
< it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid3/access.log\s+squid$}) }
< when 'Ubuntu'
< case facts[:operatingsystemrelease]
< when '14.04'
---
> context 'when on Debian' do
29a22,33
> end
> when 'Ubuntu'
> case facts[:operatingsystemrelease]
> when '14.04'
> context 'when on Ubuntu 14.04' do
> it { is_expected.to contain_package('squid3').with_ensure('present') }
> it { is_expected.to contain_service('squid3').with_ensure('running') }
> it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_group('root') }
> it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_owner('root') }
> it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid3/squid.conf') }
> it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid3/access.log\s+squid$}) }
> end
30a35,45
> context 'when on Ubuntu 16.04' do
> it { is_expected.to contain_package('squid').with_ensure('present') }
> it { is_expected.to contain_service('squid').with_ensure('running') }
> it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('root') }
> it { is_expected.to contain_concat('/etc/squid/squid.conf').with_owner('root') }
> it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid/squid.conf') }
> it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) }
> end
> end
> else
> context 'when on any other non-debian OS' do
33c48
< it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('root') }
---
> it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('squid') }
38,44d52
< else
< it { is_expected.to contain_package('squid').with_ensure('present') }
< it { is_expected.to contain_service('squid').with_ensure('running') }
< it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('squid') }
< it { is_expected.to contain_concat('/etc/squid/squid.conf').with_owner('root') }
< it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid/squid.conf') }
< it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) }
Full source of this change:
This kills all of the offenses and is much more fitted to how rubocop-rspec assumes you will write RSpec. Basically, you are writing this case statement based on data that changes in each example here but you are not actually defining new contexts to clarify that the test setup is different.
@alexjfisher what do you think of this solution?
@backus I thought that might be the solution. Thanks for confirming and taking the time to look at this.
:smile:
Moving the discussion over from #261:
From @alexjfisher
Code in question
Offenses