Skip to content

Commit 078ccda

Browse files
committed
(CONT-789) Rubocop Manual Fix 1 - RSpec/MultipleExpectations
1 parent 878476c commit 078ccda

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ RSpec/ImplicitSubject:
292292
- 'spec/functions/mysql_password_spec.rb'
293293
- 'spec/functions/mysql_strip_hash_spec.rb'
294294

295-
# Offense count: 7
296-
RSpec/MultipleExpectations:
297-
Max: 9
298-
299295
# Offense count: 36
300296
# Configuration parameters: AllowSubject.
301297
RSpec/MultipleMemoizedHelpers:

spec/acceptance/types/mysql_login_path_spec.rb

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,11 @@
8080
end
8181
it 'finds the login path #stdout' do
8282
run_shell('mysql_config_editor print --all') do |r|
83-
expect(r.stdout).to match(%r{^\[local_socket\]\n})
84-
expect(r.stdout).to match(%r{host = localhost\n})
85-
expect(r.stdout).to match(%r{user = root\n})
86-
expect(r.stdout).to match(%r{socket = /var/run/mysql/mysql.sock\n})
87-
88-
expect(r.stdout).to match(%r{^\[local_tcp\]\n})
89-
expect(r.stdout).to match(%r{host = 127.0.0.1\n})
90-
expect(r.stdout).to match(%r{user = network\n})
91-
expect(r.stdout).to match(%r{port = 3306\n})
83+
regex_match = [%r{^\[local_socket\]\n}, %r{host = localhost\n}, %r{user = root\n}, %r{socket = /var/run/mysql/mysql.sock\n},
84+
%r{^\[local_tcp\]\n}, %r{host = 127.0.0.1\n}, %r{user = network\n}, %r{port = 3306\n}]
85+
regex_match.each do |reg|
86+
expect(r.stdout).to match(reg)
87+
end
9288
expect(r.stderr).to be_empty
9389
end
9490
end
@@ -124,10 +120,10 @@
124120
end
125121
it 'finds the login path #stdout' do
126122
run_shell('mysql_config_editor print -G local_tcp') do |r|
127-
expect(r.stdout).to match(%r{^\[local_tcp\]\n})
128-
expect(r.stdout).to match(%r{host = 10.0.0.1\n})
129-
expect(r.stdout).to match(%r{user = network2\n})
130-
expect(r.stdout).to match(%r{port = 3307\n})
123+
regex_match = [%r{^\[local_tcp\]\n}, %r{host = 10.0.0.1\n}, %r{user = network2\n}, %r{port = 3307\n}]
124+
regex_match.each do |reg|
125+
expect(r.stdout).to match(reg)
126+
end
131127
expect(r.stderr).to be_empty
132128
end
133129
end
@@ -146,11 +142,14 @@
146142
end
147143
it 'ensure values are removed #stdout' do
148144
run_shell('mysql_config_editor print -G local_tcp') do |r|
149-
expect(r.stdout).to match(%r{^\[local_tcp\]\n})
150-
expect(r.stdout).to match(%r{host = 192.168.0.1\n})
151-
expect(r.stdout).not_to match(%r{host = 10.0.0.1\n})
152-
expect(r.stdout).not_to match(%r{user = network2\n})
153-
expect(r.stdout).not_to match(%r{port = 3307\n})
145+
regex_match = [%r{^\[local_tcp\]\n}, %r{host = 192.168.0.1\n}]
146+
regex_match.each do |reg|
147+
expect(r.stdout).to match(reg)
148+
end
149+
regex_no_match = [%r{host = 10.0.0.1\n}, %r{user = network2\n}, %r{port = 3307\n}]
150+
regex_no_match.each do |reg|
151+
expect(r.stdout).not_to match(reg)
152+
end
154153
expect(r.stderr).to be_empty
155154
end
156155
end
@@ -201,10 +200,10 @@
201200
end
202201
it 'finds the login path #stdout' do
203202
run_shell('MYSQL_TEST_LOGIN_FILE=/home/loginpath_test/.mylogin.cnf mysql_config_editor print -G local_tcp') do |r|
204-
expect(r.stdout).to match(%r{^\[local_tcp\]\n})
205-
expect(r.stdout).to match(%r{host = 10.0.0.2\n})
206-
expect(r.stdout).to match(%r{user = other\n})
207-
expect(r.stdout).to match(%r{port = 3306\n})
203+
regex_match = [%r{^\[local_tcp\]\n}, %r{host = 10.0.0.2\n}, %r{user = other\n}, %r{port = 3306\n}]
204+
regex_match.each do |reg|
205+
expect(r.stdout).to match(reg)
206+
end
208207
expect(r.stderr).to be_empty
209208
end
210209
end
@@ -230,10 +229,10 @@
230229
end
231230
it 'finds the login path #stdout' do
232231
run_shell('MYSQL_TEST_LOGIN_FILE=/home/loginpath_test/.mylogin.cnf mysql_config_editor print -G local_tcp') do |r|
233-
expect(r.stdout).to match(%r{^\[local_tcp\]\n})
234-
expect(r.stdout).to match(%r{host = 10.0.0.3\n})
235-
expect(r.stdout).to match(%r{user = other2\n})
236-
expect(r.stdout).to match(%r{port = 3307\n})
232+
regex_match = [%r{^\[local_tcp\]\n}, %r{host = 10.0.0.3\n}, %r{user = other2\n}, %r{port = 3307\n}]
233+
regex_match.each do |reg|
234+
expect(r.stdout).to match(reg)
235+
end
237236
expect(r.stderr).to be_empty
238237
end
239238
end

spec/unit/puppet/provider/mysql_user/mysql_spec.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,24 @@
190190

191191
describe 'create' do
192192
it 'makes a user' do
193-
expect(provider.class).to receive(:mysql_caller).with("CREATE USER 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'", 'system')
194-
expect(provider.class).to receive(:mysql_caller).with("GRANT USAGE ON *.* TO 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10", 'system') # rubocop:disable Layout/LineLength
195-
expect(provider.class).to receive(:mysql_caller).with("GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE", 'system')
193+
output = ["CREATE USER 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'",
194+
"GRANT USAGE ON *.* TO 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10",
195+
"GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"]
196+
output.each do |out|
197+
expect(provider.class).to receive(:mysql_caller).with(out, 'system')
198+
end
196199
expect(provider).to receive(:exists?).and_return(true)
197200
expect(provider.create).to be_truthy
198201
end
199202
it 'creates a user using IF NOT EXISTS' do
200203
provider.class.instance_variable_set(:@mysqld_version_string, '5.7.6')
201204

202-
expect(provider.class).to receive(:mysql_caller).with("CREATE USER IF NOT EXISTS 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'",
203-
'system')
204-
expect(provider.class).to receive(:mysql_caller).with("ALTER USER IF EXISTS 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10", 'system') # rubocop:disable Layout/LineLength
205-
expect(provider.class).to receive(:mysql_caller).with("ALTER USER 'joe'@'localhost' REQUIRE NONE", 'system')
205+
output = ["CREATE USER IF NOT EXISTS 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'",
206+
"ALTER USER IF EXISTS 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10",
207+
"ALTER USER 'joe'@'localhost' REQUIRE NONE"]
208+
output.each do |out|
209+
expect(provider.class).to receive(:mysql_caller).with(out, 'system')
210+
end
206211
expect(provider).to receive(:exists?).and_return(true)
207212
expect(provider.create).to be_truthy
208213
end

0 commit comments

Comments
 (0)