Skip to content

Commit 24d92da

Browse files
committed
(CONT-237) Rubocop - fixes for tasks
1 parent 2677ac2 commit 24d92da

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

lib/puppetlabs_spec_helper/tasks/check_symlinks.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
require 'pathspec'
44

5-
module PuppetlabsSpecHelper; end
6-
module PuppetlabsSpecHelper::Tasks; end
7-
5+
# Helpers for validating symlinks.
86
class PuppetlabsSpecHelper::Tasks::CheckSymlinks
97
DEFAULT_IGNORED = [
108
'/.git/',

lib/puppetlabs_spec_helper/tasks/fixtures.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
require 'open3'
55
require 'json'
66

7-
module PuppetlabsSpecHelper; end
8-
module PuppetlabsSpecHelper::Tasks; end
7+
# Top level namespace for spec helper tasks.
8+
module PuppetlabsSpecHelper::Tasks end
99

10+
# Helpers for workfing with fixtures.
1011
module PuppetlabsSpecHelper::Tasks::FixtureHelpers
1112
# This is a helper for the self-symlink entry of fixtures.yml
1213
def source_dir
@@ -136,8 +137,10 @@ def fixtures(category)
136137

137138
next unless include_repo?(opts['puppet_version'])
138139

140+
# rubocop:disable Security/Eval
141+
# TODO: Remove eval
139142
real_target = eval("\"#{opts['target']}\"", binding, __FILE__, __LINE__) # evaluating target reference in this context (see auto_symlink)
140-
real_source = eval("\"#{opts['repo']}\"", binding, __FILE__, __LINE__) # evaluating repo reference in this context (see auto_symlink)
143+
real_source = eval("\"#{opts['repo']}\"", binding, __FILE__, __LINE__) # evaluating repo reference in this context (see auto_symlink)t
141144

142145
result[real_source] = validate_fixture_hash!(
143146
'target' => File.join(real_target, fixture),
@@ -157,7 +160,7 @@ def validate_fixture_hash!(hash)
157160
return hash unless hash['scm'] == 'git'
158161

159162
# Forward slashes in the ref aren't allowed. And is probably a branch name.
160-
raise ArgumentError, "The ref for #{hash['target']} is invalid (Contains a forward slash). If this is a branch name, please use the 'branch' setting instead." if hash['ref'] =~ %r{/}
163+
raise ArgumentError, "The ref for #{hash['target']} is invalid (Contains a forward slash). If this is a branch name, please use the 'branch' setting instead." if hash['ref'].include?('/')
161164

162165
hash
163166
end
@@ -248,12 +251,11 @@ def git_remote_url(target)
248251
end
249252

250253
def remove_subdirectory(target, subdir)
251-
unless subdir.nil?
252-
Dir.mktmpdir do |tmpdir|
253-
FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir)
254-
FileUtils.rm_rf("#{target}/#{subdir}")
255-
FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), target.to_s)
256-
end
254+
return if subdir.nil?
255+
Dir.mktmpdir do |tmpdir|
256+
FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir)
257+
FileUtils.rm_rf("#{target}/#{subdir}")
258+
FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), target.to_s)
257259
end
258260
end
259261

@@ -284,7 +286,7 @@ def module_working_directory
284286
# so when anything else we count that as a active thread
285287
# @return [Integer] - current thread count
286288
def current_thread_count(items)
287-
active_threads = items.find_all do |_item, opts|
289+
active_threads = items.select do |_item, opts|
288290
if opts[:thread]
289291
opts[:thread].status
290292
else
@@ -316,7 +318,7 @@ def download_items(items)
316318
end
317319
else
318320
# the last thread started should be the longest wait
319-
item, item_opts = items.find_all { |_i, o| o.key?(:thread) }.last
321+
item, item_opts = items.reverse.find { |_i, o| o.key?(:thread) }
320322
logger.debug "Waiting on #{item}"
321323
item_opts[:thread].join # wait for the thread to finish
322324
# now that we waited lets try again
@@ -405,7 +407,7 @@ def download_module(remote, opts)
405407
end
406408
end
407409

408-
include PuppetlabsSpecHelper::Tasks::FixtureHelpers # DSL include # rubocop:disable Style/MixinUsage
410+
include PuppetlabsSpecHelper::Tasks::FixtureHelpers # DSL include
409411

410412
desc 'Create the fixtures directory'
411413
task :spec_prep do

0 commit comments

Comments
 (0)