Skip to content

Commit 9ab41b1

Browse files
committed
(CONT-789) Rubocop Manual Fixes 2 - RSpec/NamedSubject
1 parent eb39931 commit 9ab41b1

13 files changed

+170
-165
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-04-12 10:15:38 UTC using RuboCop version 1.48.1.
3+
# on 2023-04-12 10:17:11 UTC using RuboCop version 1.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -141,23 +141,6 @@ RSpec/ExampleLength:
141141
RSpec/MultipleMemoizedHelpers:
142142
Max: 8
143143

144-
# Offense count: 121
145-
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
146-
# SupportedStyles: always, named_only
147-
RSpec/NamedSubject:
148-
Exclude:
149-
- 'spec/classes/graceful_failures_spec.rb'
150-
- 'spec/classes/mycnf_template_spec.rb'
151-
- 'spec/classes/mysql_backup_mysqldump_spec.rb'
152-
- 'spec/classes/mysql_backup_xtrabackup_spec.rb'
153-
- 'spec/classes/mysql_client_spec.rb'
154-
- 'spec/classes/mysql_server_account_security_spec.rb'
155-
- 'spec/classes/mysql_server_backup_spec.rb'
156-
- 'spec/classes/mysql_server_spec.rb'
157-
- 'spec/defines/mysql_db_spec.rb'
158-
- 'spec/functions/mysql_normalise_and_deepmerge_spec.rb'
159-
- 'spec/functions/mysql_strip_hash_spec.rb'
160-
161144
# Offense count: 45
162145
# Configuration parameters: AllowedGroups.
163146
RSpec/NestedGroups:

spec/classes/graceful_failures_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'spec_helper'
44

55
describe 'mysql::server' do
6+
subject(:server) { described_class.new }
7+
68
context 'on an unsupported OS' do
79
let(:facts) do
810
{
@@ -12,7 +14,7 @@
1214
end
1315

1416
it 'gracefully fails' do
15-
expect(subject).to compile.and_raise_error(%r{Unsupported platform:})
17+
expect(server).to compile.and_raise_error(%r{Unsupported platform:})
1618
end
1719
end
1820
end

spec/classes/mycnf_template_spec.rb

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'spec_helper'
44

55
describe 'mysql::server' do
6+
subject(:server) { described_class.new }
7+
68
on_supported_os.each do |os, facts|
79
context "my.cnf template - on #{os}" do
810
let(:facts) do
@@ -13,16 +15,16 @@
1315
let(:params) { { override_options: { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } } }
1416

1517
it do
16-
expect(subject).to contain_file('mysql-config-file').with(mode: '0644',
17-
selinux_ignore_defaults: true).with_content(%r{socket = \/var\/lib\/mysql\/mysql.sock})
18+
expect(server).to contain_file('mysql-config-file').with(mode: '0644',
19+
selinux_ignore_defaults: true).with_content(%r{socket = \/var\/lib\/mysql\/mysql.sock})
1820
end
1921
end
2022

2123
describe 'array entry' do
2224
let(:params) { { override_options: { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'] } } } }
2325

2426
it do
25-
expect(subject).to contain_file('mysql-config-file').with_content(
27+
expect(server).to contain_file('mysql-config-file').with_content(
2628
%r{.*replicate-do-db = base1\nreplicate-do-db = base2.*},
2729
)
2830
end
@@ -80,8 +82,8 @@
8082
let(:params) { { includedir: '/etc/my.cnf.d' } }
8183

8284
it 'makes the directory' do
83-
expect(subject).to contain_file('/etc/my.cnf.d').with(ensure: :directory,
84-
mode: '0755')
85+
expect(server).to contain_file('/etc/my.cnf.d').with(ensure: :directory,
86+
mode: '0755')
8587
end
8688

8789
it { is_expected.to contain_file('mysql-config-file').with_content(%r{!includedir}) }
@@ -91,8 +93,8 @@
9193
let(:params) { { includedir: '' } }
9294

9395
it 'shouldnt contain the directory' do
94-
expect(subject).not_to contain_file('mysql-config-file').with(ensure: :directory,
95-
mode: '0755')
96+
expect(server).not_to contain_file('mysql-config-file').with(ensure: :directory,
97+
mode: '0755')
9698
end
9799

98100
it { is_expected.to contain_file('mysql-config-file').without_content(%r{!includedir}) }
@@ -102,55 +104,55 @@
102104
let(:params) { { 'config_file_mode' => '0644' } }
103105

104106
it do
105-
expect(subject).to contain_file('mysql-config-file').with(mode: '0644')
107+
expect(server).to contain_file('mysql-config-file').with(mode: '0644')
106108
end
107109
end
108110

109111
context 'with file mode 0664' do
110112
let(:params) { { 'config_file_mode' => '0664' } }
111113

112114
it do
113-
expect(subject).to contain_file('mysql-config-file').with(mode: '0664')
115+
expect(server).to contain_file('mysql-config-file').with(mode: '0664')
114116
end
115117
end
116118

117119
context 'with file mode 0660' do
118120
let(:params) { { 'config_file_mode' => '0660' } }
119121

120122
it do
121-
expect(subject).to contain_file('mysql-config-file').with(mode: '0660')
123+
expect(server).to contain_file('mysql-config-file').with(mode: '0660')
122124
end
123125
end
124126

125127
context 'with file mode 0641' do
126128
let(:params) { { 'config_file_mode' => '0641' } }
127129

128130
it do
129-
expect(subject).to contain_file('mysql-config-file').with(mode: '0641')
131+
expect(server).to contain_file('mysql-config-file').with(mode: '0641')
130132
end
131133
end
132134

133135
context 'with file mode 0610' do
134136
let(:params) { { 'config_file_mode' => '0610' } }
135137

136138
it do
137-
expect(subject).to contain_file('mysql-config-file').with(mode: '0610')
139+
expect(server).to contain_file('mysql-config-file').with(mode: '0610')
138140
end
139141
end
140142

141143
context 'with file 0600' do
142144
let(:params) { { 'config_file_mode' => '0600' } }
143145

144146
it do
145-
expect(subject).to contain_file('mysql-config-file').with(mode: '0600')
147+
expect(server).to contain_file('mysql-config-file').with(mode: '0600')
146148
end
147149
end
148150

149151
context 'user owner 12345' do
150152
let(:params) { { 'mycnf_owner' => '12345' } }
151153

152154
it do
153-
expect(subject).to contain_file('mysql-config-file').with(
155+
expect(server).to contain_file('mysql-config-file').with(
154156
owner: '12345',
155157
)
156158
end
@@ -160,7 +162,7 @@
160162
let(:params) { { 'mycnf_group' => '12345' } }
161163

162164
it do
163-
expect(subject).to contain_file('mysql-config-file').with(
165+
expect(server).to contain_file('mysql-config-file').with(
164166
group: '12345',
165167
)
166168
end
@@ -170,7 +172,7 @@
170172
let(:params) { { 'mycnf_owner' => '12345', 'mycnf_group' => '12345' } }
171173

172174
it do
173-
expect(subject).to contain_file('mysql-config-file').with(
175+
expect(server).to contain_file('mysql-config-file').with(
174176
owner: '12345',
175177
group: '12345',
176178
)

spec/classes/mysql_backup_mysqldump_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'spec_helper'
44

55
describe 'mysql::backup::mysqldump' do
6+
subject(:backup_mysqldump) { described_class.new }
7+
68
on_supported_os.each do |os, facts|
79
context "on #{os}" do
810
let(:pre_condition) do
@@ -30,7 +32,7 @@ class { 'mysql::server': }
3032
end
3133

3234
it {
33-
expect(subject).to contain_cron('mysql-backup').with(
35+
expect(backup_mysqldump).to contain_cron('mysql-backup').with(
3436
hour: 23,
3537
minute: 59,
3638
monthday: 30,
@@ -44,7 +46,7 @@ class { 'mysql::server': }
4446
let(:params) { default_params }
4547

4648
it {
47-
expect(subject).to contain_cron('mysql-backup').with(
49+
expect(backup_mysqldump).to contain_cron('mysql-backup').with(
4850
command: '/usr/local/sbin/mysqlbackup.sh',
4951
ensure: 'present',
5052
hour: 23,
@@ -62,13 +64,13 @@ class { 'mysql::server': }
6264
end
6365

6466
it {
65-
expect(subject).to contain_file('mysqlbackup.sh').with_content(
67+
expect(backup_mysqldump).to contain_file('mysqlbackup.sh').with_content(
6668
%r{(\| TEST -TEST)},
6769
)
68-
expect(subject).to contain_file('mysqlbackup.sh').with_content(
70+
expect(backup_mysqldump).to contain_file('mysqlbackup.sh').with_content(
6971
%r{(\.TEST)},
7072
)
71-
expect(subject).not_to contain_package('bzip2')
73+
expect(backup_mysqldump).not_to contain_package('bzip2')
7274
}
7375
end
7476

@@ -81,7 +83,7 @@ class { 'mysql::server': }
8183
end
8284

8385
it {
84-
expect(subject).to contain_file('mysqlbackup.sh').with_content(
86+
expect(backup_mysqldump).to contain_file('mysqlbackup.sh').with_content(
8587
%r{information_schema},
8688
)
8789
}

0 commit comments

Comments
 (0)