Skip to content

Commit 0db7f4d

Browse files
committed
((CONT-799) Rubocop Fixes 16-20
- Rspec/MultipleMemorizedHelpers - Rspec/NestedGroups - RspecRepeatedExampleGroupBody - Rspec/RepeatedExampleGroupDescription - Style/MixinUsage
1 parent 9446785 commit 0db7f4d

File tree

5 files changed

+50
-76
lines changed

5 files changed

+50
-76
lines changed

.rubocop_todo.yml

+1-27
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ RSpec/ImplicitSubject:
3333
- 'spec/defines/resolver_spec.rb'
3434
- 'spec/defines/userlist_spec.rb'
3535

36-
# Offense count: 3
37-
# Configuration parameters: AllowSubject.
38-
RSpec/MultipleMemoizedHelpers:
39-
Max: 6
40-
4136
# Offense count: 96
4237
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
4338
# SupportedStyles: always, named_only
@@ -46,12 +41,7 @@ RSpec/NamedSubject:
4641
- 'spec/classes/haproxy_spec.rb'
4742
- 'spec/defines/instance_service_spec.rb'
4843
- 'spec/defines/instance_spec.rb'
49-
50-
# Offense count: 30
51-
# Configuration parameters: AllowedGroups.
52-
RSpec/NestedGroups:
53-
Max: 5
54-
44+
5545
# Offense count: 183
5646
# Configuration parameters: AllowedPatterns.
5747
# AllowedPatterns: ^expect_, ^assert_
@@ -66,19 +56,3 @@ RSpec/NoExpectationExample:
6656
- 'spec/classes/haproxy_spec.rb'
6757
- 'spec/defines/instance_service_spec.rb'
6858
- 'spec/defines/instance_spec.rb'
69-
70-
# Offense count: 2
71-
RSpec/RepeatedExampleGroupBody:
72-
Exclude:
73-
- 'spec/acceptance/basic_spec.rb'
74-
75-
# Offense count: 4
76-
RSpec/RepeatedExampleGroupDescription:
77-
Exclude:
78-
- 'spec/acceptance/listen_spec.rb'
79-
- 'spec/defines/instance_spec.rb'
80-
81-
# Offense count: 1
82-
Style/MixinUsage:
83-
Exclude:
84-
- 'spec/spec_helper.rb'

spec/acceptance/basic_spec.rb

+37-39
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ class { 'haproxy':
2929
end
3030
end
3131

32-
describe port('9090') do
33-
it { is_expected.not_to be_listening }
34-
end
35-
36-
describe port('9091') do
37-
it { is_expected.not_to be_listening }
32+
['9090', '9091'].each do |port|
33+
describe port(port) do
34+
it { is_expected.not_to be_listening }
35+
end
3836
end
3937
end
4038

@@ -93,43 +91,43 @@ class { 'haproxy': }
9391
end
9492
end
9593
end
94+
end
9695

97-
context 'when "httpchk" option is defined and $sort_options_aphabetic => true' do
98-
pp_httpchk_option = <<-PUPPETCODE
99-
class { 'haproxy::globals':
100-
sort_options_alphabetic => true,
101-
}
102-
class { 'haproxy': }
103-
haproxy::listen { 'stats':
104-
ipaddress => '127.0.0.1',
105-
ports => ['9091'],
106-
mode => 'http',
107-
}
108-
haproxy::backend { 'servers':
109-
mode => 'http',
110-
sort_options_alphabetic => true,
111-
options => {
112-
'option' => [
113-
'httpchk',
114-
],
115-
'http-check' => 'disable-on-404',
116-
'server' => [
117-
'srv1 127.0.0.1:9091 check',
118-
],
119-
},
120-
}
121-
PUPPETCODE
96+
describe 'when "httpchk" option is defined and $sort_options_aphabetic => true' do
97+
pp_httpchk_option = <<-PUPPETCODE
98+
class { 'haproxy::globals':
99+
sort_options_alphabetic => true,
100+
}
101+
class { 'haproxy': }
102+
haproxy::listen { 'stats':
103+
ipaddress => '127.0.0.1',
104+
ports => ['9091'],
105+
mode => 'http',
106+
}
107+
haproxy::backend { 'servers':
108+
mode => 'http',
109+
sort_options_alphabetic => true,
110+
options => {
111+
'option' => [
112+
'httpchk',
113+
],
114+
'http-check' => 'disable-on-404',
115+
'server' => [
116+
'srv1 127.0.0.1:9091 check',
117+
],
118+
},
119+
}
120+
PUPPETCODE
122121

123-
it 'overrides $sort_options_aphabetic to false and warn' do
124-
apply_manifest(pp_httpchk_option, catch_failures: true) do |r|
125-
expect(r.stderr).to contain %r{Overriding\sthe\svalue\sof\s\$sort_options_alphabetic\sto\s"false"\sdue\sto\s"httpchk"\soption\sdefined}
126-
end
122+
it 'overrides $sort_options_aphabetic to false and warn' do
123+
apply_manifest(pp_httpchk_option, catch_failures: true) do |r|
124+
expect(r.stderr).to contain %r{Overriding\sthe\svalue\sof\s\$sort_options_alphabetic\sto\s"false"\sdue\sto\s"httpchk"\soption\sdefined}
127125
end
126+
end
128127

129-
describe file('/etc/haproxy/haproxy.cfg') do
130-
its(:content) do
131-
is_expected.to match %r{backend\sservers\n\s+mode\shttp\n\s+option\shttpchk\n\s+http-check\s+disable-on-404}
132-
end
128+
describe file('/etc/haproxy/haproxy.cfg') do # rubocop:disable RSpec/NestedGroups
129+
its(:content) do
130+
is_expected.to match %r{backend\sservers\n\s+mode\shttp\n\s+option\shttpchk\n\s+http-check\s+disable-on-404}
133131
end
134132
end
135133
end

spec/classes/haproxy_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
)
123123
end
124124

125-
describe 'Base concat fragment contents' do
125+
describe 'Base concat fragment contents' do # rubocop:disable RSpec/NestedGroups
126126
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") }
127127

128128
# C9936 C9937
@@ -225,7 +225,7 @@
225225
)
226226
end
227227

228-
describe 'Base concat fragment contents' do
228+
describe 'Base concat fragment contents' do # rubocop:disable RSpec/NestedGroups
229229
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") }
230230

231231
it 'contains global and defaults sections' do
@@ -312,7 +312,7 @@
312312
)
313313
end
314314

315-
describe 'Base concat fragment contents' do
315+
describe 'Base concat fragment contents' do # rubocop:disable RSpec/NestedGroups
316316
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") }
317317

318318
# C9936 C9937
@@ -388,7 +388,7 @@
388388
)
389389
end
390390

391-
describe 'Base concat fragment contents' do
391+
describe 'Base concat fragment contents' do # rubocop:disable RSpec/NestedGroups
392392
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") }
393393

394394
it 'contains global and defaults sections' do

spec/defines/instance_spec.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'spec_helper'
44

55
describe 'haproxy::instance' do
6+
# rubocop:disable RSpec/NestedGroups
67
let(:default_facts) do
78
{
89
concat_basedir: '/dne',
@@ -18,7 +19,7 @@
1819

1920
# haproxy::instance with service name "haproxy".
2021

21-
context 'when on supported platforms' do
22+
context 'with haproxy::instance with service name "haproxy' do
2223
let(:title) { 'haproxy' }
2324

2425
describe 'for OS-agnostic configuration' do
@@ -218,7 +219,7 @@
218219
)
219220
end
220221

221-
describe 'Base concat fragment contents' do
222+
describe 'Base concat fragment contents' do # rubocop:disable RSpec/MultipleMemoizedHelpers
222223
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") }
223224

224225
it 'contains global and defaults sections' do
@@ -288,7 +289,7 @@
288289

289290
# haproxy::instance with 2nd instance and with non-standard service name.
290291

291-
context 'when on supported platforms' do
292+
context 'with haproxy::instance with 2nd instance and with non-standard service name' do
292293
let(:title) { 'group1' }
293294

294295
describe 'for OS-agnostic configuration' do
@@ -471,7 +472,7 @@
471472
)
472473
end
473474

474-
describe 'Base concat fragment contents' do
475+
describe 'Base concat fragment contents' do # rubocop:disable RSpec/MultipleMemoizedHelpers
475476
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-group1-haproxy-base', 'content').split("\n") }
476477

477478
it 'contains global and defaults sections' do
@@ -639,7 +640,7 @@
639640
)
640641
end
641642

642-
describe 'Base concat fragment contents' do
643+
describe 'Base concat fragment contents' do # rubocop:disable RSpec/MultipleMemoizedHelpers
643644
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") }
644645

645646
it 'contains global and defaults sections' do
@@ -739,4 +740,5 @@
739740
}.to raise_error(Puppet::Error, %r{operating system is not supported with the haproxy module})
740741
end
741742
end
743+
# rubocop:enable RSpec/NestedGroups
742744
end

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb'))
1111

12-
include RspecPuppetFacts
12+
include RspecPuppetFacts # rubocop:disable Style/MixinUsage
1313

1414
default_facts = {
1515
puppetversion: Puppet.version,

0 commit comments

Comments
 (0)