Skip to content

Commit 0f6a609

Browse files
committed
(maint) Refactor aggregate testing
Previously the tests use private instance methods to verify the object, however the each_list method now does that. This commit changes the tests to use this method instead.
1 parent 7e6ac3b commit 0f6a609

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

spec/languageserver-sidecar/integration/puppet-languageserver-sidecar/featureflag_puppetstrings/featureflag_puppetstrings_spec.rb

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,10 @@ def expect_same_array_content(a, b)
111111
deserial2 = PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata.new()
112112
expect { deserial2.from_json!(result2) }.to_not raise_error
113113

114-
deserial.class
115-
.instance_methods(false)
116-
.reject { |name| %i[to_json from_json! each_list append!].include?(name) }
117-
.each do |method_name|
118-
# There should be at least one item
119-
expect(deserial.send(method_name).count).to be > 0
120-
# Before and after should be the same
121-
expect_same_array_content(deserial.send(method_name), deserial2.send(method_name))
114+
deserial.each_list do |key, value|
115+
# There should be at least one item per list in the aggregate
116+
expect(value.count).to be > 0
117+
expect_same_array_content(value, deserial2.send(key))
122118
end
123119
end
124120
end
@@ -270,7 +266,7 @@ def expect_same_array_content(a, b)
270266
describe 'when running workspace_aggregate action' do
271267
let (:cmd_options) { ['--action', 'workspace_aggregate', '--local-workspace', workspace] }
272268

273-
it 'should return a cachable deserializable aggregate object with all default metadata' do
269+
it 'should return a cachable deserializable aggregate object with all workspace metadata' do
274270
expect_empty_cache
275271

276272
result = run_sidecar(cmd_options)
@@ -286,14 +282,10 @@ def expect_same_array_content(a, b)
286282
deserial2 = PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata.new()
287283
expect { deserial2.from_json!(result2) }.to_not raise_error
288284

289-
deserial.class
290-
.instance_methods(false)
291-
.reject { |name| %i[to_json from_json! each_list append!].include?(name) }
292-
.each do |method_name|
293-
# There should be at least one item
294-
expect(deserial.send(method_name).count).to be > 0
295-
# Before and after should be the same
296-
expect_same_array_content(deserial.send(method_name), deserial2.send(method_name))
285+
deserial.each_list do |key, value|
286+
# There should be at least one item per list in the aggregate
287+
expect(value.count).to be > 0
288+
expect_same_array_content(value, deserial2.send(key))
297289
end
298290
end
299291
end
@@ -429,14 +421,10 @@ def expect_same_array_content(a, b)
429421
deserial2 = PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata.new()
430422
expect { deserial2.from_json!(result2) }.to_not raise_error
431423

432-
deserial.class
433-
.instance_methods(false)
434-
.reject { |name| %i[to_json from_json! each_list append!].include?(name) }
435-
.each do |method_name|
436-
# There should be at least one item
437-
expect(deserial.send(method_name).count).to be > 0
438-
# Before and after should be the same
439-
expect_same_array_content(deserial.send(method_name), deserial2.send(method_name))
424+
deserial.each_list do |key, value|
425+
# There should be at least one item per list in the aggregate
426+
expect(value.count).to be > 0
427+
expect_same_array_content(value, deserial2.send(key))
440428
end
441429
end
442430
end

0 commit comments

Comments
 (0)