rspec-puppet 2.12.0 → 3.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +139 -483
- data/README.md +18 -5
- data/bin/rspec-puppet-init +4 -3
- data/lib/rspec-puppet/adapters.rb +67 -61
- data/lib/rspec-puppet/cache.rb +3 -2
- data/lib/rspec-puppet/consts.rb +16 -14
- data/lib/rspec-puppet/coverage.rb +37 -42
- data/lib/rspec-puppet/errors.rb +6 -6
- data/lib/rspec-puppet/example/application_example_group.rb +3 -1
- data/lib/rspec-puppet/example/class_example_group.rb +3 -1
- data/lib/rspec-puppet/example/define_example_group.rb +3 -1
- data/lib/rspec-puppet/example/function_example_group.rb +28 -23
- data/lib/rspec-puppet/example/host_example_group.rb +3 -1
- data/lib/rspec-puppet/example/provider_example_group.rb +2 -0
- data/lib/rspec-puppet/example/type_alias_example_group.rb +4 -2
- data/lib/rspec-puppet/example/type_example_group.rb +3 -1
- data/lib/rspec-puppet/example.rb +6 -7
- data/lib/rspec-puppet/facter_impl.rb +11 -10
- data/lib/rspec-puppet/matchers/allow_value.rb +10 -10
- data/lib/rspec-puppet/matchers/compile.rb +54 -61
- data/lib/rspec-puppet/matchers/count_generic.rb +18 -18
- data/lib/rspec-puppet/matchers/create_generic.rb +66 -78
- data/lib/rspec-puppet/matchers/dynamic_matchers.rb +13 -2
- data/lib/rspec-puppet/matchers/include_class.rb +5 -4
- data/lib/rspec-puppet/matchers/parameter_matcher.rb +11 -12
- data/lib/rspec-puppet/matchers/raise_error.rb +5 -1
- data/lib/rspec-puppet/matchers/run.rb +41 -44
- data/lib/rspec-puppet/matchers/type_matchers.rb +37 -48
- data/lib/rspec-puppet/matchers.rb +2 -0
- data/lib/rspec-puppet/monkey_patches/win32/registry.rb +7 -5
- data/lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb +3 -1
- data/lib/rspec-puppet/monkey_patches/windows/taskschedulerconstants.rb +208 -205
- data/lib/rspec-puppet/monkey_patches.rb +56 -56
- data/lib/rspec-puppet/rake_task.rb +6 -4
- data/lib/rspec-puppet/raw_string.rb +2 -0
- data/lib/rspec-puppet/sensitive.rb +9 -7
- data/lib/rspec-puppet/setup.rb +43 -48
- data/lib/rspec-puppet/spec_helper.rb +2 -0
- data/lib/rspec-puppet/support.rb +133 -134
- data/lib/rspec-puppet/tasks/release_test.rb +8 -5
- data/lib/rspec-puppet/version.rb +5 -0
- data/lib/rspec-puppet.rb +43 -51
- metadata +11 -9
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
|
3
5
|
# Load this library before enabling the monkey-patches to avoid HI-581
|
4
6
|
begin
|
5
|
-
require 'hiera/util/win32'
|
7
|
+
require 'hiera/util/win32'
|
6
8
|
rescue LoadError
|
7
9
|
# ignore this on installs without hiera, e.g. puppet 3 gems
|
8
10
|
end
|
@@ -21,15 +23,15 @@ class RSpec::Puppet::EventListener
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
def self.example_passed(
|
26
|
+
def self.example_passed(_example)
|
25
27
|
@rspec_puppet_example = false
|
26
28
|
end
|
27
29
|
|
28
|
-
def self.example_pending(
|
30
|
+
def self.example_pending(_example)
|
29
31
|
@rspec_puppet_example = false
|
30
32
|
end
|
31
33
|
|
32
|
-
def self.example_failed(
|
34
|
+
def self.example_failed(_example)
|
33
35
|
@rspec_puppet_example = false
|
34
36
|
end
|
35
37
|
|
@@ -38,19 +40,18 @@ class RSpec::Puppet::EventListener
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def self.rspec3?
|
41
|
-
if @rspec3.nil?
|
42
|
-
@rspec3 = defined?(RSpec::Core::Notifications)
|
43
|
-
end
|
43
|
+
@rspec3 = defined?(RSpec::Core::Notifications) if @rspec3.nil?
|
44
44
|
|
45
45
|
@rspec3
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
class << self
|
49
|
+
attr_reader :current_example
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
RSpec.configuration.reporter.register_listener(RSpec::Puppet::EventListener, :example_started, :example_pending,
|
53
|
+
RSpec.configuration.reporter.register_listener(RSpec::Puppet::EventListener, :example_started, :example_pending,
|
54
|
+
:example_passed, :example_failed)
|
54
55
|
|
55
56
|
require 'rspec-puppet/monkey_patches/win32/taskscheduler'
|
56
57
|
require 'rspec-puppet/monkey_patches/win32/registry'
|
@@ -84,24 +85,20 @@ module Puppet
|
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
87
|
-
retval = old_set_default.
|
88
|
+
retval = old_set_default.bind_call(self, attr)
|
88
89
|
|
89
|
-
unless old_posix.nil?
|
90
|
-
|
91
|
-
end
|
92
|
-
unless old_microsoft_windows.nil?
|
93
|
-
Puppet.features.add(:microsoft_windows) { old_microsoft_windows }
|
94
|
-
end
|
90
|
+
Puppet.features.add(:posix) { old_posix } unless old_posix.nil?
|
91
|
+
Puppet.features.add(:microsoft_windows) { old_microsoft_windows } unless old_microsoft_windows.nil?
|
95
92
|
|
96
93
|
retval
|
97
94
|
else
|
98
|
-
old_set_default.
|
95
|
+
old_set_default.bind_call(self, attr)
|
99
96
|
end
|
100
97
|
end
|
101
98
|
end
|
102
99
|
|
103
100
|
module Parser::Files
|
104
|
-
alias
|
101
|
+
alias old_find_manifests_in_modules find_manifests_in_modules
|
105
102
|
module_function :old_find_manifests_in_modules
|
106
103
|
|
107
104
|
def find_manifests_in_modules(pattern, environment)
|
@@ -113,8 +110,9 @@ module Puppet
|
|
113
110
|
RSpec::Puppet::Consts.stub_consts_for(RSpec.configuration.platform)
|
114
111
|
end
|
115
112
|
|
116
|
-
if pretending && pretending != Puppet::Util::Platform.actual_platform
|
117
|
-
|
113
|
+
if pretending && pretending != Puppet::Util::Platform.actual_platform && environment.respond_to?(:value_cache,
|
114
|
+
true)
|
115
|
+
environment.send(:value_cache).clear
|
118
116
|
end
|
119
117
|
output = old_find_manifests_in_modules(pattern, environment)
|
120
118
|
|
@@ -135,30 +133,30 @@ module Puppet
|
|
135
133
|
# Fix for removal of default_env function
|
136
134
|
# Bug: https://github.com/rodjek/rspec-puppet/issues/796
|
137
135
|
# Upstream: https://github.com/puppetlabs/puppet/commit/94df3c1a3992d89b2d7d5db8a70373c135bdd86b
|
138
|
-
|
139
|
-
def default_env
|
136
|
+
unless respond_to?(:default_env)
|
137
|
+
def default_env
|
140
138
|
DEFAULT_ENV
|
141
139
|
end
|
142
140
|
module_function :default_env
|
143
141
|
end
|
144
142
|
|
145
143
|
if respond_to?(:get_env)
|
146
|
-
alias
|
144
|
+
alias old_get_env get_env
|
147
145
|
module_function :old_get_env
|
148
146
|
|
149
147
|
def get_env(name, mode = default_env)
|
150
148
|
if RSpec::Puppet.rspec_puppet_example?
|
151
149
|
# use the actual platform, not the pretended
|
152
|
-
|
150
|
+
old_get_env(name, Platform.actual_platform)
|
153
151
|
else
|
154
|
-
|
152
|
+
old_get_env(name, mode)
|
155
153
|
end
|
156
154
|
end
|
157
155
|
module_function :get_env
|
158
156
|
end
|
159
157
|
|
160
158
|
if respond_to?(:path_to_uri)
|
161
|
-
alias
|
159
|
+
alias old_path_to_uri path_to_uri
|
162
160
|
module_function :old_path_to_uri
|
163
161
|
|
164
162
|
def path_to_uri(*args)
|
@@ -175,12 +173,12 @@ module Puppet
|
|
175
173
|
|
176
174
|
# Allow rspec-puppet to pretend to be different platforms.
|
177
175
|
module Platform
|
178
|
-
alias
|
176
|
+
alias old_windows? windows?
|
179
177
|
module_function :old_windows?
|
180
178
|
|
181
179
|
def windows?
|
182
180
|
if RSpec::Puppet.rspec_puppet_example?
|
183
|
-
|
181
|
+
pretending? ? pretend_windows? : (actual_platform == :windows)
|
184
182
|
else
|
185
183
|
old_windows?
|
186
184
|
end
|
@@ -249,7 +247,7 @@ module Puppet
|
|
249
247
|
if RSpec::Puppet.rspec_puppet_example?
|
250
248
|
true
|
251
249
|
else
|
252
|
-
old_pass.
|
250
|
+
old_pass.bind_call(self, value)
|
253
251
|
end
|
254
252
|
end
|
255
253
|
end
|
@@ -263,7 +261,7 @@ module Puppet
|
|
263
261
|
if RSpec::Puppet.rspec_puppet_example?
|
264
262
|
true
|
265
263
|
else
|
266
|
-
old_pass.
|
264
|
+
old_pass.bind_call(self, value)
|
267
265
|
end
|
268
266
|
end
|
269
267
|
end
|
@@ -285,7 +283,7 @@ module Puppet
|
|
285
283
|
return config unless config.nil? && RSpec.configuration.fallback_to_default_hiera
|
286
284
|
end
|
287
285
|
end
|
288
|
-
old_hiera_conf_file.
|
286
|
+
old_hiera_conf_file.bind_call(self)
|
289
287
|
end
|
290
288
|
end
|
291
289
|
|
@@ -295,10 +293,15 @@ module Puppet
|
|
295
293
|
if RSpec::Puppet.rspec_puppet_example?
|
296
294
|
env = lookup_invocation.scope.environment
|
297
295
|
mod = env.module(module_name)
|
298
|
-
|
296
|
+
unless mod
|
297
|
+
raise Puppet::DataBinding::LookupError,
|
298
|
+
format(_("Environment '%<env>s', cannot find module '%<module_name>s'"), env: env.name,
|
299
|
+
module_name: module_name)
|
300
|
+
end
|
301
|
+
|
299
302
|
return Pathname.new(mod.hiera_conf_file)
|
300
303
|
end
|
301
|
-
old_configuration_path.
|
304
|
+
old_configuration_path.bind_call(self, lookup_invocation)
|
302
305
|
end
|
303
306
|
end
|
304
307
|
end
|
@@ -308,29 +311,26 @@ class Pathname
|
|
308
311
|
def rspec_puppet_basename(path)
|
309
312
|
raise ArgumentError, 'pathname stubbing not enabled' unless RSpec.configuration.enable_pathname_stubbing
|
310
313
|
|
311
|
-
|
312
|
-
path = path[2..-1]
|
313
|
-
end
|
314
|
+
path = path[2..-1] if /\A[a-zA-Z]:(#{SEPARATOR_PAT}.*)\z/.match?(path)
|
314
315
|
path.split(SEPARATOR_PAT).last || path[/(#{SEPARATOR_PAT})/, 1] || path
|
315
316
|
end
|
316
317
|
|
317
|
-
if instance_methods.include?(
|
318
|
+
if instance_methods.include?('chop_basename')
|
318
319
|
old_chop_basename = instance_method(:chop_basename)
|
319
320
|
|
320
321
|
define_method(:chop_basename) do |path|
|
321
322
|
if RSpec::Puppet.rspec_puppet_example?
|
322
323
|
if RSpec.configuration.enable_pathname_stubbing
|
323
324
|
base = rspec_puppet_basename(path)
|
324
|
-
if /\A#{SEPARATOR_PAT}?\z/o
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
end
|
325
|
+
return nil if /\A#{SEPARATOR_PAT}?\z/o.match?(base)
|
326
|
+
|
327
|
+
[path[0, path.rindex(base)], base]
|
328
|
+
|
329
329
|
else
|
330
|
-
old_chop_basename.
|
330
|
+
old_chop_basename.bind_call(self, path)
|
331
331
|
end
|
332
332
|
else
|
333
|
-
old_chop_basename.
|
333
|
+
old_chop_basename.bind_call(self, path)
|
334
334
|
end
|
335
335
|
end
|
336
336
|
end
|
@@ -345,10 +345,8 @@ class Puppet::Module
|
|
345
345
|
old_match_manifests = instance_method(:match_manifests)
|
346
346
|
|
347
347
|
define_method(:match_manifests) do |rest|
|
348
|
-
result = old_match_manifests.
|
349
|
-
if result.length > 1 && File.basename(result[0]) == 'init.pp'
|
350
|
-
result.shift
|
351
|
-
end
|
348
|
+
result = old_match_manifests.bind_call(self, rest)
|
349
|
+
result.shift if result.length > 1 && File.basename(result[0]) == 'init.pp'
|
352
350
|
result
|
353
351
|
end
|
354
352
|
end
|
@@ -361,7 +359,7 @@ Puppet::Type.type(:file).paramclass(:path).munge do |value|
|
|
361
359
|
if RSpec::Puppet.rspec_puppet_example?
|
362
360
|
value
|
363
361
|
else
|
364
|
-
file_path_munge.
|
362
|
+
file_path_munge.bind_call(self, value)
|
365
363
|
end
|
366
364
|
end
|
367
365
|
|
@@ -373,7 +371,7 @@ Puppet::Type.type(:exec).paramclass(:user).validate do |value|
|
|
373
371
|
if RSpec::Puppet.rspec_puppet_example?
|
374
372
|
true
|
375
373
|
else
|
376
|
-
exec_user_validate.
|
374
|
+
exec_user_validate.bind_call(self, value)
|
377
375
|
end
|
378
376
|
end
|
379
377
|
|
@@ -383,11 +381,11 @@ end
|
|
383
381
|
Puppet::Type.type(:file).provide(:windows).class_eval do
|
384
382
|
old_supports_acl = instance_method(:supports_acl?) if respond_to?(:supports_acl?)
|
385
383
|
|
386
|
-
def supports_acl?(
|
384
|
+
def supports_acl?(_path)
|
387
385
|
if RSpec::Puppet.rspec_puppet_example?
|
388
386
|
true
|
389
387
|
else
|
390
|
-
old_supports_acl.
|
388
|
+
old_supports_acl.bind_call(self, value)
|
391
389
|
end
|
392
390
|
end
|
393
391
|
|
@@ -397,7 +395,7 @@ Puppet::Type.type(:file).provide(:windows).class_eval do
|
|
397
395
|
if RSpec::Puppet.rspec_puppet_example?
|
398
396
|
true
|
399
397
|
else
|
400
|
-
old_manages_symlinks.
|
398
|
+
old_manages_symlinks.bind_call(self, value)
|
401
399
|
end
|
402
400
|
end
|
403
401
|
end
|
@@ -406,9 +404,11 @@ end
|
|
406
404
|
# windows, otherwise it will require other libraries that probably won't be
|
407
405
|
# available on non-windows hosts.
|
408
406
|
module Kernel
|
409
|
-
alias
|
407
|
+
alias old_require require
|
410
408
|
def require(path)
|
411
|
-
return if
|
409
|
+
return if ['puppet/util/windows',
|
410
|
+
'win32/registry'].include?(path) && RSpec::Puppet.rspec_puppet_example? && Puppet::Util::Platform.pretend_windows?
|
411
|
+
|
412
412
|
old_require(path)
|
413
413
|
end
|
414
414
|
end
|
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake'
|
2
4
|
require 'rspec/core/rake_task'
|
3
5
|
|
4
|
-
desc
|
6
|
+
desc 'Run all RSpec code examples'
|
5
7
|
RSpec::Core::RakeTask.new(:rspec) do |t|
|
6
|
-
File.exist?('spec/spec.opts') ?
|
8
|
+
opts = File.exist?('spec/spec.opts') ? File.read('spec/spec.opts').chomp : ''
|
7
9
|
t.rspec_opts = opts
|
8
10
|
end
|
9
11
|
|
10
|
-
SPEC_SUITES = (Dir.entries('spec') - ['.', '..','fixtures']).select {|e| File.directory? "spec/#{e}" }
|
12
|
+
SPEC_SUITES = (Dir.entries('spec') - ['.', '..', 'fixtures']).select { |e| File.directory? "spec/#{e}" }
|
11
13
|
namespace :rspec do
|
12
14
|
SPEC_SUITES.each do |suite|
|
13
15
|
desc "Run #{suite} RSpec code examples"
|
14
16
|
RSpec::Core::RakeTask.new(suite) do |t|
|
15
17
|
t.pattern = "spec/#{suite}/**/*_spec.rb"
|
16
|
-
File.exist?('spec/spec.opts') ?
|
18
|
+
opts = File.exist?('spec/spec.opts') ? File.read('spec/spec.opts').chomp : ''
|
17
19
|
t.rspec_opts = opts
|
18
20
|
end
|
19
21
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RSpec::Puppet
|
2
4
|
if defined?(::Puppet::Pops::Types::PSensitiveType::Sensitive)
|
3
5
|
# A wrapper representing Sensitive data type, eg. in class params.
|
@@ -27,12 +29,12 @@ module RSpec::Puppet
|
|
27
29
|
# If compared to Puppet Sensitive type, it compares the wrapped values.
|
28
30
|
|
29
31
|
# @param other [#unwrap, Object] value to compare to
|
30
|
-
def ==
|
32
|
+
def ==(other)
|
31
33
|
if other.respond_to? :unwrap
|
32
|
-
if unwrap.
|
33
|
-
|
34
|
+
if unwrap.is_a?(Regexp)
|
35
|
+
unwrap =~ other.unwrap
|
34
36
|
else
|
35
|
-
|
37
|
+
unwrap == other.unwrap
|
36
38
|
end
|
37
39
|
else
|
38
40
|
super
|
@@ -40,12 +42,12 @@ module RSpec::Puppet
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
else
|
43
|
-
|
45
|
+
# :nocov:
|
44
46
|
class Sensitive
|
45
|
-
def initialize(
|
47
|
+
def initialize(_value)
|
46
48
|
raise 'The use of the Sensitive data type is not supported by this Puppet version'
|
47
49
|
end
|
48
50
|
end
|
49
|
-
|
51
|
+
# :nocov:
|
50
52
|
end
|
51
53
|
end
|
data/lib/rspec-puppet/setup.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
1
4
|
require 'puppet'
|
2
5
|
require 'fileutils'
|
3
6
|
|
@@ -9,17 +12,17 @@ end
|
|
9
12
|
|
10
13
|
module RSpec::Puppet
|
11
14
|
class Setup
|
12
|
-
def self.run(module_name=nil)
|
15
|
+
def self.run(module_name = nil)
|
13
16
|
unless is_module_dir?
|
14
|
-
|
17
|
+
warn 'Does not appear to be a Puppet module. Aborting'
|
15
18
|
return false
|
16
19
|
end
|
17
20
|
|
18
21
|
if control_repo?
|
19
|
-
|
20
|
-
Unable to find a metadata.json file. If this is a module, please create a
|
21
|
-
metadata.json file and try again.
|
22
|
-
END
|
22
|
+
warn <<~END
|
23
|
+
Unable to find a metadata.json file. If this is a module, please create a
|
24
|
+
metadata.json file and try again.
|
25
|
+
END
|
23
26
|
return false
|
24
27
|
end
|
25
28
|
|
@@ -30,16 +33,16 @@ END
|
|
30
33
|
safe_create_rakefile
|
31
34
|
end
|
32
35
|
|
33
|
-
def self.safe_setup_directories(module_name=nil, verbose=true)
|
36
|
+
def self.safe_setup_directories(module_name = nil, verbose = true)
|
34
37
|
if control_repo?
|
35
|
-
|
38
|
+
warn 'Unable to setup rspec-puppet automatically in a control repo' if verbose
|
36
39
|
return false
|
37
40
|
end
|
38
41
|
|
39
42
|
if module_name.nil?
|
40
43
|
module_name = get_module_name
|
41
44
|
if module_name.nil?
|
42
|
-
|
45
|
+
warn 'Unable to determine module name. Aborting' if verbose
|
43
46
|
return false
|
44
47
|
end
|
45
48
|
end
|
@@ -52,35 +55,35 @@ END
|
|
52
55
|
File.join('spec', 'hosts'),
|
53
56
|
File.join('spec', 'fixtures'),
|
54
57
|
File.join('spec', 'fixtures', 'manifests'),
|
55
|
-
File.join('spec', 'fixtures', 'modules')
|
58
|
+
File.join('spec', 'fixtures', 'modules')
|
56
59
|
].each { |dir| safe_mkdir(dir, verbose) }
|
57
60
|
|
58
61
|
target = File.join('spec', 'fixtures', 'modules', module_name)
|
59
62
|
safe_make_link('.', target, verbose)
|
60
63
|
end
|
61
64
|
|
62
|
-
def self.safe_teardown_links(module_name=nil)
|
65
|
+
def self.safe_teardown_links(module_name = nil)
|
63
66
|
if module_name.nil?
|
64
67
|
module_name = get_module_name
|
65
68
|
if module_name.nil?
|
66
|
-
|
69
|
+
warn 'Unable to determine module name. Aborting'
|
67
70
|
return false
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
74
|
target = File.join('spec', 'fixtures', 'modules', module_name)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
+
return unless File.symlink?(target) && File.readlink(target) == File.expand_path('.')
|
76
|
+
|
77
|
+
File.unlink(target)
|
75
78
|
end
|
76
|
-
|
79
|
+
|
77
80
|
def self.control_repo?
|
78
81
|
!File.exist?('metadata.json')
|
79
82
|
end
|
80
83
|
|
81
84
|
def self.get_module_name
|
82
85
|
module_name = nil
|
83
|
-
Dir[
|
86
|
+
Dir['manifests/*.pp'].entries.each do |manifest|
|
84
87
|
module_name = get_module_name_from_file(manifest)
|
85
88
|
break unless module_name.nil?
|
86
89
|
end
|
@@ -100,23 +103,19 @@ END
|
|
100
103
|
p.string = File.read(file)
|
101
104
|
tokens = p.fullscan
|
102
105
|
|
103
|
-
i = tokens.index { |token| [
|
104
|
-
unless i.nil?
|
105
|
-
module_name = tokens[i + 1].last[:value].split('::').first
|
106
|
-
end
|
106
|
+
i = tokens.index { |token| %i[CLASS DEFINE].include? token.first }
|
107
|
+
module_name = tokens[i + 1].last[:value].split('::').first unless i.nil?
|
107
108
|
|
108
109
|
module_name
|
109
110
|
end
|
110
111
|
|
111
112
|
def self.is_module_dir?
|
112
|
-
Dir[
|
113
|
+
Dir['*'].entries.include? 'manifests'
|
113
114
|
end
|
114
115
|
|
115
|
-
def self.safe_mkdir(dir, verbose=true)
|
116
|
+
def self.safe_mkdir(dir, verbose = true)
|
116
117
|
if File.exist? dir
|
117
|
-
unless File.directory? dir
|
118
|
-
$stderr.puts "!! #{dir} already exists and is not a directory"
|
119
|
-
end
|
118
|
+
warn "!! #{dir} already exists and is not a directory" unless File.directory? dir
|
120
119
|
else
|
121
120
|
begin
|
122
121
|
FileUtils.mkdir dir
|
@@ -129,9 +128,7 @@ END
|
|
129
128
|
|
130
129
|
def self.safe_touch(file)
|
131
130
|
if File.exist? file
|
132
|
-
unless File.file? file
|
133
|
-
$stderr.puts "!! #{file} already exists and is not a regular file"
|
134
|
-
end
|
131
|
+
warn "!! #{file} already exists and is not a regular file" unless File.file? file
|
135
132
|
else
|
136
133
|
FileUtils.touch file
|
137
134
|
puts " + #{file}"
|
@@ -141,9 +138,7 @@ END
|
|
141
138
|
def self.safe_create_file(filename, content)
|
142
139
|
if File.exist? filename
|
143
140
|
old_content = File.read(filename)
|
144
|
-
if old_content != content
|
145
|
-
$stderr.puts "!! #{filename} already exists and differs from template"
|
146
|
-
end
|
141
|
+
warn "!! #{filename} already exists and differs from template" if old_content != content
|
147
142
|
else
|
148
143
|
File.open(filename, 'w') do |f|
|
149
144
|
f.puts content
|
@@ -169,17 +164,17 @@ END
|
|
169
164
|
Dir.respond_to?(:junction?) ? Dir.junction?(target) : File.symlink?(target)
|
170
165
|
end
|
171
166
|
|
172
|
-
def self.safe_make_link(source, target, verbose=true)
|
167
|
+
def self.safe_make_link(source, target, verbose = true)
|
173
168
|
if File.exist?(target) && !link?(target)
|
174
|
-
|
169
|
+
warn "!! #{target} already exists and is not a symlink"
|
175
170
|
return
|
176
171
|
end
|
177
172
|
|
178
173
|
return if link_to_source?(target, source)
|
179
174
|
|
180
175
|
if Puppet::Util::Platform.windows?
|
181
|
-
output = `call mklink /J "#{target.
|
182
|
-
unless
|
176
|
+
output = `call mklink /J "#{target.tr('/', '\\')}" "#{source}"`
|
177
|
+
unless $CHILD_STATUS.success?
|
183
178
|
puts output
|
184
179
|
abort
|
185
180
|
end
|
@@ -194,19 +189,19 @@ END
|
|
194
189
|
end
|
195
190
|
|
196
191
|
def self.safe_create_rakefile
|
197
|
-
content =
|
198
|
-
require 'rspec-puppet/rake_task'
|
192
|
+
content = <<~EOF
|
193
|
+
require 'rspec-puppet/rake_task'
|
199
194
|
|
200
|
-
begin
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
rescue Gem::LoadError
|
207
|
-
|
208
|
-
end
|
209
|
-
EOF
|
195
|
+
begin
|
196
|
+
if Gem::Specification::find_by_name('puppet-lint')
|
197
|
+
require 'puppet-lint/tasks/puppet-lint'
|
198
|
+
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "vendor/**/*.pp"]
|
199
|
+
task :default => [:rspec, :lint]
|
200
|
+
end
|
201
|
+
rescue Gem::LoadError
|
202
|
+
task :default => :rspec
|
203
|
+
end
|
204
|
+
EOF
|
210
205
|
safe_create_file('Rakefile', content)
|
211
206
|
end
|
212
207
|
end
|