Skip to content

Commit 14ae34b

Browse files
author
David Swan
committed
RubocopFunctionsFinished
1 parent e5b9276 commit 14ae34b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+337
-266
lines changed

.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,6 @@ Style/AsciiComments:
9595
Style/IfUnlessModifier:
9696
Enabled: false
9797
Style/SymbolProc:
98-
Enabled: false
98+
Enabled: false
99+
RSpec/NamedSubject:
100+
Enabled: false

spec/functions/deep_merge_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
arguments = { 'key1' => 'value1' }, { 'key2' => 'value2' }
4747
originals = [arguments[0].dup, arguments[1].dup]
4848
it 'does not change the original hashes' do
49-
subject.call([arguments[0], arguments[1]]) # rubocop:disable RSpec/NamedSubject
49+
subject.call([arguments[0], arguments[1]])
5050
arguments.each_with_index do |argument, index|
5151
expect(argument).to eq(originals[index])
5252
end

spec/functions/get_module_path_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(path)
2525

2626
it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
2727

28-
context 'when the modulepath is a list' do
28+
context 'when the modulepath is a list' do # rubocop:disable RSpec/NestedGroups
2929
before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' }
3030

3131
it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
@@ -39,7 +39,7 @@ def initialize(path)
3939

4040
it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
4141

42-
context 'when the modulepath is a list' do
42+
context 'when the modulepath is a list' do # rubocop:disable RSpec/NestedGroups
4343
before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' }
4444

4545
it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }

spec/functions/getvar_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
it { is_expected.not_to eq(nil) }
55
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
66
it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
7-
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
87

98
it { is_expected.to run.with_params('$::foo').and_return(nil) }
109

spec/functions/is_a_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
end
2424

2525
it 'suceeds when comparing an UTF8 and double byte characters' do
26-
is_expected.to run.with_params('このテキスト', String).and_return(true)
27-
is_expected.to run.with_params('ŧћịś ŧêχŧ', String).and_return(true)
26+
comparison_array = ['このテキスト', 'ŧћịś ŧêχŧ']
27+
comparison_array.each do |comparison_value|
28+
is_expected.to run.with_params(comparison_value, String).and_return(true)
29+
end
2830
end
2931
end
3032
end

spec/functions/is_array_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
it { is_expected.to run.with_params(1).and_return(false) }
1818
it { is_expected.to run.with_params({}).and_return(false) }
1919
context 'Checking for deprecation warning' do
20-
after(:all) do
20+
after(:each) do
2121
ENV.delete('STDLIB_LOG_DEPRECATIONS')
2222
end
2323
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_bool_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
it { is_expected.to run.with_params('true').and_return(false) }
1414
it { is_expected.to run.with_params('false').and_return(false) }
1515
context 'Checking for deprecation warning' do
16-
after(:all) do
16+
after(:each) do
1717
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1818
end
1919
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_domain_name_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
it { is_expected.to run.with_params('www.foo-bar.example.com').and_return(true) }
2929
it { is_expected.to run.with_params('www.foo-bar.example.com.').and_return(true) }
3030
it { is_expected.to run.with_params('-foo.example.com').and_return(false) }
31-
it { is_expected.to run.with_params('-foo.example.com').and_return(false) }
31+
it { is_expected.to run.with_params('-foo.example.com.').and_return(false) }
3232
end
3333
# Values obtained from Facter values will be frozen strings
3434
# in newer versions of Facter:

spec/functions/is_float_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
end
2323

2424
context 'Checking for deprecation warning' do
25-
after(:all) do
25+
after(:each) do
2626
ENV.delete('STDLIB_LOG_DEPRECATIONS')
2727
end
2828
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_integer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
it { is_expected.to run.with_params(3.7).and_return(false) }
1717
it { is_expected.to run.with_params('3.7').and_return(false) }
1818
it { is_expected.to run.with_params(-3.7).and_return(false) }
19-
it { is_expected.to run.with_params('3.7').and_return(false) }
19+
it { is_expected.to run.with_params('-3.7').and_return(false) }
2020

2121
it { is_expected.to run.with_params('one').and_return(false) }
2222
it { is_expected.to run.with_params([]).and_return(false) }
@@ -28,7 +28,7 @@
2828
it { is_expected.to run.with_params("foo\nbar").and_return(false) }
2929

3030
context 'Checking for deprecation warning' do
31-
after(:all) do
31+
after(:each) do
3232
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3333
end
3434
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_ip_address_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
scope.expects(:warning).with(includes('This method is deprecated')).never
3434
is_expected.to run.with_params('1.2.3.4').and_return(true)
3535
end
36-
after(:all) do
36+
after(:each) do
3737
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3838
end
3939
end

spec/functions/is_ipv4_address_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414

1515
context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
16-
after(:all) do
16+
after(:each) do
1717
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1818
end
1919
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_ipv6_address_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
it { is_expected.to run.with_params('one').and_return(false) }
1212

1313
context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
14-
after(:all) do
14+
after(:each) do
1515
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1616
end
1717
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_numeric_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
it { is_expected.to run.with_params(3.7).and_return(true) }
1515
it { is_expected.to run.with_params('3.7').and_return(true) }
1616
it { is_expected.to run.with_params(-3.7).and_return(true) }
17-
it { is_expected.to run.with_params('3.7').and_return(true) }
17+
it { is_expected.to run.with_params('-3.7').and_return(true) }
1818

1919
it { is_expected.to run.with_params('-342.2315e-12').and_return(true) }
2020

@@ -28,7 +28,7 @@
2828
it { is_expected.to run.with_params(' - 1234').and_return(false) }
2929

3030
context 'Checking for deprecation warning' do
31-
after(:all) do
31+
after(:each) do
3232
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3333
end
3434
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_string_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
it { is_expected.to run.with_params(3.7).and_return(false) }
1717
it { is_expected.to run.with_params('3.7').and_return(false) }
1818
it { is_expected.to run.with_params(-3.7).and_return(false) }
19-
it { is_expected.to run.with_params('3.7').and_return(false) }
19+
it { is_expected.to run.with_params('-3.7').and_return(false) }
2020

2121
it { is_expected.to run.with_params([]).and_return(false) }
2222
it { is_expected.to run.with_params([1]).and_return(false) }
@@ -27,7 +27,7 @@
2727
it { is_expected.to run.with_params('0001234').and_return(true) }
2828

2929
context 'Checking for deprecation warning' do
30-
after(:all) do
30+
after(:each) do
3131
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3232
end
3333
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/load_module_metadata_spec.rb

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,38 @@
77

88
describe 'when calling with valid arguments' do
99
before :each do
10-
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
11-
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
10+
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
11+
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
1212
end
1313

1414
context 'when calling with valid utf8 and double byte character arguments' do
1515
before :each do
16-
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, encoding: 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
16+
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
1717
この文字"}')
18-
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
18+
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
1919
この文字"}')
2020
end
2121

22+
let(:prefix) { 'C:' if Puppet::Util::Platform.windows? }
23+
2224
it 'jsons parse the file' do
23-
if Puppet::Util::Platform.windows?
24-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
25-
allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(true)
26-
allow(File).to receive(:read).with('C:/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
27-
else
28-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
29-
allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(true)
30-
allow(File).to receive(:read).with('/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
31-
end
25+
allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
26+
allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(true)
27+
allow(File).to receive(:read).with("#{prefix}/path/to/module/metadata.json").and_return('{"name": "spencer-science"}')
3228

3329
result = subject.call(['science'])
3430
expect(result['name']).to eq('spencer-science')
3531
end
3632

3733
it 'fails by default if there is no metadata.json' do
38-
if Puppet::Util::Platform.windows?
39-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
40-
allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false)
41-
else
42-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
43-
allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
44-
end
34+
allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
35+
allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
4536
expect { subject.call(['science']) }.to raise_error(Puppet::ParseError)
4637
end
4738

4839
it 'returns nil if user allows empty metadata.json' do
49-
if Puppet::Util::Platform.windows?
50-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
51-
allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false)
52-
else
53-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
54-
allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
55-
end
40+
allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
41+
allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
5642
result = subject.call(['science', true])
5743
expect(result).to eq({})
5844
end

spec/functions/loadjson_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
describe 'when calling with valid arguments' do
88
before :each do
9-
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
10-
allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
9+
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
10+
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
1111
end
1212

1313
context 'when a non-existing file is specified' do

spec/functions/parsejson_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
end
2323

2424
it 'is able to parse empty JSON values' do
25-
is_expected.to run.with_params('[]')
26-
.and_return([])
27-
is_expected.to run.with_params('{}')
28-
.and_return({})
25+
actual_array = %w[[] {}]
26+
expected = [[], {}]
27+
actual_array.each_with_index do |actual, index|
28+
is_expected.to run.with_params(actual).and_return(expected[index])
29+
end
2930
end
3031

3132
it 'is able to parse JSON data with a mixed structure' do

spec/functions/parseyaml_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
context 'with correct YAML data' do
1414
it 'is able to parse a YAML data with a String' do
15-
is_expected.to run.with_params('--- just a string')
16-
.and_return('just a string')
17-
is_expected.to run.with_params('just a string')
18-
.and_return('just a string')
15+
actual_array = ['--- just a string', 'just a string']
16+
actual_array.each do |actual|
17+
is_expected.to run.with_params(actual).and_return('just a string')
18+
end
1919
end
2020

2121
it 'is able to parse YAML data with a Hash' do

spec/functions/private_spec.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
describe 'private' do
44
it 'issues a warning' do
5-
scope.expects(:warning).with("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.")
5+
scope.expects(:warning).with("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Metrics/LineLength : unable to cut line to required length
66
begin
77
subject.call []
8-
rescue
8+
rescue # rubocop:disable Lint/HandleExceptions
99
# ignore this
1010
end
1111
end
@@ -36,9 +36,7 @@
3636
scope.expects(:lookupvar).with('caller_module_name').returns('bar')
3737
scope.source.expects(:name).returns('foo::baz')
3838
scope.source.expects(:type).returns('hostclass')
39-
expect {
40-
subject.call []
41-
}.to raise_error Puppet::ParseError, %r{Class foo::baz is private}
39+
expect { subject.call [] }.to raise_error Puppet::ParseError, %r{Class foo::baz is private}
4240
end
4341
end
4442

@@ -48,9 +46,7 @@
4846
scope.expects(:lookupvar).with('caller_module_name').returns('bar')
4947
scope.source.expects(:name).returns('foo::baz')
5048
scope.source.expects(:type).returns('definition')
51-
expect {
52-
subject.call []
53-
}.to raise_error Puppet::ParseError, %r{Definition foo::baz is private}
49+
expect { subject.call [] }.to raise_error Puppet::ParseError, %r{Definition foo::baz is private}
5450
end
5551
end
5652
end

spec/functions/pw_hash_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
end
5454

5555
context 'when running on a platform with a weak String#crypt implementation' do
56-
before(:each) { allow_any_instance_of(String).to receive(:crypt).with('$1$1').and_return('a bad hash') }
56+
before(:each) { allow_any_instance_of(String).to receive(:crypt).with('$1$1').and_return('a bad hash') } # rubocop:disable RSpec/AnyInstance : Unable to find a viable replacement
5757

5858
it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_raise_error(Puppet::ParseError, %r{system does not support enhanced salts}) }
5959
end
@@ -68,7 +68,10 @@
6868
if Puppet::Util::Package.versioncmp(Puppet.version, '4.7.0') >= 0
6969
describe 'when arguments are sensitive' do
7070
it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', 'salt').and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
71-
it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
71+
it {
72+
is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt'))
73+
.and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0')
74+
}
7275
it { is_expected.to run.with_params('password', 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
7376
end
7477
end

0 commit comments

Comments
 (0)