Skip to content

Commit 0298868

Browse files
committed
(CONT-801) Autocorrect safe group 4
1 parent 76b40d3 commit 0298868

17 files changed

+56
-68
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -140,45 +140,11 @@ RSpec/ContextWording:
140140
RSpec/DescribeClass:
141141
Enabled: false
142142

143-
# Offense count: 25
144-
# This cop supports safe autocorrection (--autocorrect).
145-
RSpec/EmptyLineAfterExampleGroup:
146-
Exclude:
147-
- 'spec/functions/defined_with_params_spec.rb'
148-
- 'spec/functions/stdlib_ensure_spec.rb'
149-
- 'spec/functions/swapcase_spec.rb'
150-
- 'spec/functions/validate_cmd_spec.rb'
151-
- 'spec/type_aliases/email_spec.rb'
152-
- 'spec/type_aliases/ensure_package_spec.rb'
153-
- 'spec/unit/facter/util/puppet_settings_spec.rb'
154-
- 'spec/unit/puppet/provider/file_line/ruby_spec.rb'
155-
- 'spec/unit/puppet/provider/file_line/ruby_spec_alter.rb'
156-
157-
# Offense count: 13
158-
# This cop supports safe autocorrection (--autocorrect).
159-
# Configuration parameters: AllowConsecutiveOneLiners.
160-
RSpec/EmptyLineAfterHook:
161-
Exclude:
162-
- 'spec/functions/delete_undef_values_spec.rb'
163-
- 'spec/functions/deprecation_spec.rb'
164-
- 'spec/functions/get_module_path_spec.rb'
165-
- 'spec/functions/loadjson_spec.rb'
166-
- 'spec/functions/time_spec.rb'
167-
- 'spec/unit/puppet/provider/file_line/ruby_spec_alter.rb'
168-
169143
# Offense count: 10
170144
# Configuration parameters: CountAsOne.
171145
RSpec/ExampleLength:
172146
Max: 9
173147

174-
# Offense count: 1
175-
# This cop supports safe autocorrection (--autocorrect).
176-
# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples.
177-
# DisallowedExamples: works
178-
RSpec/ExampleWording:
179-
Exclude:
180-
- 'spec/functions/validate_legacy_spec.rb'
181-
182148
# Offense count: 2
183149
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
184150
# Include: **/*_spec*rb*, **/spec/**/*
@@ -187,12 +153,6 @@ RSpec/FilePath:
187153
- 'spec/unit/puppet/provider/file_line/ruby_spec_alter.rb'
188154
- 'spec/unit/puppet/provider/file_line/ruby_spec_use_cases.rb'
189155

190-
# Offense count: 1
191-
# This cop supports safe autocorrection (--autocorrect).
192-
RSpec/HooksBeforeExamples:
193-
Exclude:
194-
- 'spec/functions/deprecation_spec.rb'
195-
196156
# Offense count: 198
197157
# This cop supports safe autocorrection (--autocorrect).
198158
# Configuration parameters: EnforcedStyle.
@@ -240,16 +200,6 @@ RSpec/PendingWithoutReason:
240200
- 'spec/functions/is_a_spec.rb'
241201
- 'spec/functions/type_of_spec.rb'
242202

243-
# Offense count: 13
244-
# This cop supports safe autocorrection (--autocorrect).
245-
RSpec/ReceiveNever:
246-
Exclude:
247-
- 'spec/functions/deprecation_spec.rb'
248-
- 'spec/functions/loadjson_spec.rb'
249-
- 'spec/functions/loadyaml_spec.rb'
250-
- 'spec/functions/validate_legacy_spec.rb'
251-
- 'spec/unit/facter/util/puppet_settings_spec.rb'
252-
253203
# Offense count: 4
254204
RSpec/RepeatedExampleGroupDescription:
255205
Exclude:

spec/functions/defined_with_params_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
describe 'when no resource is specified' do
77
it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
88
end
9+
910
describe 'when compared against a resource with no attributes' do
1011
let :pre_condition do
1112
'user { "dan": }'
@@ -52,6 +53,7 @@
5253
context 'with reference' do
5354
it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) }
5455
end
56+
5557
if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
5658
context 'with array' do
5759
it 'fails' do

spec/functions/delete_undef_values_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
2020
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == :undef && is_puppet_6
2121
end
22+
2223
it { is_expected.to run.with_params([undef_value]).and_return([]) }
2324
it { is_expected.to run.with_params(['one', undef_value, 'two', 'three']).and_return(['one', 'two', 'three']) }
2425
it { is_expected.to run.with_params(['ớņέ', undef_value, 'ŧשּׁō', 'ŧħґëə']).and_return(['ớņέ', 'ŧשּׁō', 'ŧħґëə']) }
@@ -42,6 +43,7 @@
4243
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
4344
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == :undef && is_puppet_6
4445
end
46+
4547
it { is_expected.to run.with_params('key' => undef_value).and_return({}) }
4648

4749
it {

spec/functions/deprecation_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
Puppet.settings[:strict] = :warning
1010
end
1111

12+
after(:each) do
13+
# this is to reset the strict variable to default
14+
Puppet.settings[:strict] = :warning
15+
end
16+
1217
it { is_expected.not_to eq(nil) }
1318
it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
1419

@@ -36,34 +41,31 @@
3641

3742
it 'fails twice with message, with multiple calls. when strict= :error' do
3843
Puppet.settings[:strict] = :error
39-
expect(Puppet).to receive(:warning).with(include('heelo')).never
44+
expect(Puppet).not_to receive(:warning).with(include('heelo'))
4045
(0..1).each do |_i|
4146
is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, %r{deprecation. key. heelo})
4247
end
4348
end
4449

4550
it 'displays nothing, despite multiple calls. strict= :off' do
4651
Puppet.settings[:strict] = :off
47-
expect(Puppet).to receive(:warning).with(include('heelo')).never
52+
expect(Puppet).not_to receive(:warning).with(include('heelo'))
4853
(0..1).each do |_i|
4954
is_expected.to run.with_params('key', 'heelo')
5055
end
5156
end
52-
53-
after(:each) do
54-
# this is to reset the strict variable to default
55-
Puppet.settings[:strict] = :warning
56-
end
5757
end
5858
elsif Puppet.version.to_f < 4.0
5959
# Puppet version < 4 will use these tests.
6060
describe 'deprecation' do
6161
after(:each) do
6262
ENV.delete('STDLIB_LOG_DEPRECATIONS')
6363
end
64+
6465
before(:each) do
6566
ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
6667
end
68+
6769
it { is_expected.not_to eq(nil) }
6870
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
6971

spec/functions/get_module_path_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def initialize(path)
3030
before(:each) do
3131
allow(Puppet::Module).to receive(:find).with('foo', 'rp_env').and_return(path_of_module_foo)
3232
end
33+
3334
it 'runs against foo' do
3435
is_expected.to run.with_params('foo').and_return(path_of_module_foo.path)
3536
end
@@ -47,6 +48,7 @@ def initialize(path)
4748
before(:each) do
4849
allow(Puppet::Module).to receive(:find).with('foo', 'test').and_return(path_of_module_foo)
4950
end
51+
5052
it 'runs against foo' do
5153
is_expected.to run.with_params('foo').and_return(path_of_module_foo.path)
5254
end

spec/functions/loadjson_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
before(:each) do
2929
allow(File).to receive(:exists?).with(filename).and_return(false).once
3030
if Puppet::PUPPETVERSION[0].to_i < 8
31-
allow(PSON).to receive(:load).never
31+
allow(PSON).not_to receive(:load)
3232
else
33-
allow(JSON).to receive(:parse).never
33+
allow(JSON).not_to receive(:parse)
3434
end
3535
end
36+
3637
it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
3738
it { is_expected.to run.with_params(filename, 'đẽƒằưļŧ' => '٧ẵłựέ').and_return('đẽƒằưļŧ' => '٧ẵłựέ') }
3839
it { is_expected.to run.with_params(filename, 'デフォルト' => '値').and_return('デフォルト' => '値') }
@@ -59,6 +60,7 @@
5960
allow(JSON).to receive(:parse).with(json).and_return(data).once
6061
end
6162
end
63+
6264
it { is_expected.to run.with_params(filename).and_return(data) }
6365
end
6466

@@ -81,6 +83,7 @@
8183
allow(JSON).to receive(:parse).with(json).once.and_raise StandardError, 'Something terrible have happened!'
8284
end
8385
end
86+
8487
it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
8588
end
8689

spec/functions/loadyaml_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
it "'default' => 'value'" do
1313
expect(File).to receive(:exists?).with(filename).and_return(false).once
14-
expect(YAML).to receive(:load_file).never
14+
expect(YAML).not_to receive(:load_file)
1515
is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
1616
end
1717
end

spec/functions/stdlib_ensure_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
it { is_expected.to run.with_params(true).and_return('present') }
88
it { is_expected.to run.with_params(false).and_return('absent') }
99
end
10+
1011
context 'work with service resource' do
1112
it { is_expected.to run.with_params('present', 'service').and_return('running') }
1213
it { is_expected.to run.with_params(true, 'service').and_return('running') }
1314
it { is_expected.to run.with_params('absent', 'service').and_return('stopped') }
1415
it { is_expected.to run.with_params(false, 'service').and_return('stopped') }
1516
end
17+
1618
['directory', 'link', 'mounted', 'file'].each do |resource|
1719
context "work with #{resource} resource" do
1820
it { is_expected.to run.with_params('present', resource).and_return(resource) }

spec/functions/swapcase_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
it { is_expected.to run.with_params('ONE').and_return('one') }
2222
it { is_expected.to run.with_params('oNe').and_return('OnE') }
2323
end
24+
2425
describe 'with arrays as inputs' do
2526
it { is_expected.to run.with_params([]).and_return([]) }
2627

@@ -33,13 +34,15 @@
3334
it { is_expected.to run.with_params(['ONE', 'OnE']).and_return(['one', 'oNe']) }
3435
it { is_expected.to run.with_params(['oNe', 'one']).and_return(['OnE', 'ONE']) }
3536
end
37+
3638
describe 'containing mixed types' do
3739
it { is_expected.to run.with_params(['OnE', {}]).and_return(['oNe', {}]) }
3840
it { is_expected.to run.with_params(['OnE', 1]).and_return(['oNe', 1]) }
3941
it { is_expected.to run.with_params(['OnE', []]).and_return(['oNe', []]) }
4042
it { is_expected.to run.with_params(['OnE', ['two']]).and_return(['oNe', ['two']]) }
4143
end
4244
end
45+
4346
it 'accepts objects which extend String' do
4447
is_expected.to run.with_params(AlsoString.new('OnE')).and_return('oNe')
4548
end

spec/functions/time_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
test_time = Time.utc(2006, 10, 13, 8, 15, 11)
1313
allow(Time).to receive(:new).with(no_args).and_return(test_time).once
1414
end
15+
1516
it { is_expected.to run.with_params.and_return(1_160_727_311) }
1617
it { is_expected.to run.with_params('').and_return(1_160_727_311) }
1718
it { is_expected.to run.with_params([]).and_return(1_160_727_311) }

spec/functions/validate_cmd_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
it { is_expected.to run.with_params('', "#{touch} % /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
3838
end
39+
3940
context 'without % placeholder' do
4041
it {
4142
is_expected.to run

spec/functions/validate_legacy_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
describe 'when passing the type assertion' do
1111
it 'passes with a deprecation warning' do
1212
expect(subject.func).to receive(:call_function).with('deprecation', 'validate_legacy', include('deprecated')).once
13-
expect(scope).to receive(:function_validate_foo).never
14-
expect(Puppet).to receive(:notice).never
13+
expect(scope).not_to receive(:function_validate_foo)
14+
expect(Puppet).not_to receive(:notice)
1515
is_expected.to run.with_params('Integer', 'validate_foo', 5)
1616
end
1717
end
1818

1919
describe 'when failing the type assertion' do
2020
it 'fails with a helpful message' do
2121
expect(subject.func).to receive(:call_function).with('deprecation', 'validate_legacy', include('deprecated')).once
22-
expect(scope).to receive(:function_validate_foo).never
22+
expect(scope).not_to receive(:function_validate_foo)
2323
expect(subject.func).to receive(:call_function).with('fail', 'validate_legacy(Integer, ...) expects an Integer value, got String').once
2424
is_expected.to run.with_params('Integer', 'validate_foo', '5')
2525
end
@@ -28,17 +28,17 @@
2828
describe 'when passing in undef' do
2929
it 'works' do
3030
expect(subject.func).to receive(:call_function).with('deprecation', 'validate_legacy', include('deprecated')).once
31-
expect(scope).to receive(:function_validate_foo).never
32-
expect(Puppet).to receive(:notice).never
31+
expect(scope).not_to receive(:function_validate_foo)
32+
expect(Puppet).not_to receive(:notice)
3333
is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef)
3434
end
3535
end
3636

3737
describe 'when passing in multiple arguments' do
3838
it 'passes with a deprecation message' do
3939
expect(subject.func).to receive(:call_function).with('deprecation', 'validate_legacy', include('deprecated')).once
40-
expect(scope).to receive(:function_validate_foo).never
41-
expect(Puppet).to receive(:notice).never
40+
expect(scope).not_to receive(:function_validate_foo)
41+
expect(Puppet).not_to receive(:notice)
4242
is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef, 1, 'foo')
4343
end
4444
end

spec/type_aliases/email_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
end
3737
end
3838
end
39+
3940
describe 'invalid handling' do
4041
['plainaddress',
4142
'#@%^%#$@#$@#.com',

spec/type_aliases/ensure_package_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
end
2121
end
2222
end
23+
2324
describe 'No complex types can match' do
2425
context 'Garbage inputs, no complex or non string types can match' do
2526
[

spec/unit/facter/util/puppet_settings_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
end
1616

1717
it 'does not yield to the block' do
18-
expect(Puppet).to receive(:[]).never
18+
expect(Puppet).not_to receive(:[])
1919
expect(subject.with_puppet { Puppet[:vardir] }).to be_nil
2020
end
2121
end
22+
2223
context 'with Puppet loaded' do
2324
# module Puppet
2425
module Puppet; end

spec/unit/puppet/provider/file_line/ruby_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
expect(provider).to be_exists
4242
end
4343
end
44+
4445
context 'when line does not exist' do
4546
let(:content) { 'foo bar' }
4647

@@ -132,6 +133,7 @@
132133
expect(File.read(tmpfile).chomp).to eql("foo\nbar")
133134
end
134135
end
136+
135137
context 'when not matching' do
136138
let(:content) { "foo3\nbar" }
137139

0 commit comments

Comments
 (0)