Skip to content

Commit ddf19d5

Browse files
authored
Merge pull request #379 from puppetlabs/CONT-515-fix_uninitialized_constant_error
(CONT-515) Fix uninitialized constant error
2 parents 047caf7 + ca4e730 commit ddf19d5

File tree

6 files changed

+510
-502
lines changed

6 files changed

+510
-502
lines changed

.rubocop.yml

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ Style/BlockDelimiters:
3636
Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to
3737
be consistent then.
3838
EnforcedStyle: braces_for_chaining
39-
Style/ClassAndModuleChildren:
40-
Description: Compact style reduces the required amount of indentation.
41-
EnforcedStyle: compact
4239
Style/EmptyElse:
4340
Description: Enforce against empty else clauses, but allow `nil` for clarity.
4441
EnforcedStyle: empty

lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb

+43-41
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,58 @@
66
require 'tempfile'
77
require 'pathname'
88

9-
# A support module for testing files.
10-
module PuppetlabsSpec::Files
11-
# This code exists only to support tests that run as root, pretty much.
12-
# Once they have finally been eliminated this can all go... --daniel 2011-04-08
13-
def self.in_tmp(path)
14-
tempdir = Dir.tmpdir
15-
16-
Pathname.new(path).ascend do |dir|
17-
return true if File.identical?(tempdir, dir)
18-
end
9+
module PuppetlabsSpec
10+
# A support module for testing files.
11+
module Files
12+
# This code exists only to support tests that run as root, pretty much.
13+
# Once they have finally been eliminated this can all go... --daniel 2011-04-08
14+
def self.in_tmp(path)
15+
tempdir = Dir.tmpdir
16+
17+
Pathname.new(path).ascend do |dir|
18+
return true if File.identical?(tempdir, dir)
19+
end
1920

20-
false
21-
end
21+
false
22+
end
2223

23-
def self.cleanup
24-
$global_tempfiles ||= []
25-
while (path = $global_tempfiles.pop)
26-
raise "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
24+
def self.cleanup
25+
$global_tempfiles ||= []
26+
while (path = $global_tempfiles.pop)
27+
raise "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
2728

28-
begin
29-
FileUtils.rm_r path, secure: true
30-
rescue Errno::ENOENT
31-
# nothing to do
29+
begin
30+
FileUtils.rm_r path, secure: true
31+
rescue Errno::ENOENT
32+
# nothing to do
33+
end
3234
end
3335
end
34-
end
3536

36-
def make_absolute(path)
37-
path = File.expand_path(path)
38-
path[0] = 'c' if Puppet.features.microsoft_windows?
39-
path
40-
end
37+
def make_absolute(path)
38+
path = File.expand_path(path)
39+
path[0] = 'c' if Puppet.features.microsoft_windows?
40+
path
41+
end
4142

42-
def tmpfilename(name)
43-
# Generate a temporary file, just for the name...
44-
source = Tempfile.new(name)
45-
path = source.path
46-
source.close!
43+
def tmpfilename(name)
44+
# Generate a temporary file, just for the name...
45+
source = Tempfile.new(name)
46+
path = source.path
47+
source.close!
4748

48-
# ...record it for cleanup,
49-
$global_tempfiles ||= []
50-
$global_tempfiles << File.expand_path(path)
49+
# ...record it for cleanup,
50+
$global_tempfiles ||= []
51+
$global_tempfiles << File.expand_path(path)
5152

52-
# ...and bam.
53-
path
54-
end
53+
# ...and bam.
54+
path
55+
end
5556

56-
def tmpdir(name)
57-
path = tmpfilename(name)
58-
FileUtils.mkdir_p(path)
59-
path
57+
def tmpdir(name)
58+
path = tmpfilename(name)
59+
FileUtils.mkdir_p(path)
60+
path
61+
end
6062
end
6163
end
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
# frozen_string_literal: true
22

3-
# This module provides some helper methods to assist with fixtures. It's
4-
# methods are designed to help when you have a conforming fixture layout so we
5-
# get project consistency.
6-
module PuppetlabsSpec::Fixtures
7-
# Returns the joined path of the global FIXTURE_DIR plus any path given to it
8-
def fixtures(*rest)
9-
File.join(PuppetlabsSpec::FIXTURE_DIR, *rest)
10-
end
11-
12-
# Returns the path to your relative fixture dir. So if your spec test is
13-
# <project>/spec/unit/facter/foo_spec.rb then your relative dir will be
14-
# <project>/spec/fixture/unit/facter/foo
15-
def my_fixture_dir
16-
callers = caller
17-
while (line = callers.shift)
18-
next unless (found = line.match(%r{/spec/(.*)_spec\.rb:}))
19-
20-
return fixtures(found[1])
3+
module PuppetlabsSpec
4+
# This module provides some helper methods to assist with fixtures. It's
5+
# methods are designed to help when you have a conforming fixture layout so we
6+
# get project consistency.
7+
module Fixtures
8+
# Returns the joined path of the global FIXTURE_DIR plus any path given to it
9+
def fixtures(*rest)
10+
File.join(PuppetlabsSpec::FIXTURE_DIR, *rest)
2111
end
22-
raise "sorry, I couldn't work out your path from the caller stack!"
23-
end
2412

25-
# Given a name, returns the full path of a file from your relative fixture
26-
# dir as returned by my_fixture_dir.
27-
def my_fixture(name)
28-
file = File.join(my_fixture_dir, name)
29-
unless File.readable? file
30-
raise "fixture '#{name}' for #{my_fixture_dir} is not readable"
13+
# Returns the path to your relative fixture dir. So if your spec test is
14+
# <project>/spec/unit/facter/foo_spec.rb then your relative dir will be
15+
# <project>/spec/fixture/unit/facter/foo
16+
def my_fixture_dir
17+
callers = caller
18+
while (line = callers.shift)
19+
next unless (found = line.match(%r{/spec/(.*)_spec\.rb:}))
20+
21+
return fixtures(found[1])
22+
end
23+
raise "sorry, I couldn't work out your path from the caller stack!"
3124
end
3225

33-
file
34-
end
26+
# Given a name, returns the full path of a file from your relative fixture
27+
# dir as returned by my_fixture_dir.
28+
def my_fixture(name)
29+
file = File.join(my_fixture_dir, name)
30+
unless File.readable? file
31+
raise "fixture '#{name}' for #{my_fixture_dir} is not readable"
32+
end
3533

36-
# Return the contents of the file using read when given a name. Uses
37-
# my_fixture to work out the relative path.
38-
def my_fixture_read(name)
39-
File.read(my_fixture(name))
40-
end
34+
file
35+
end
4136

42-
# Provides a block mechanism for iterating across the files in your fixture
43-
# area.
44-
def my_fixtures(glob = '*', flags = 0, &block)
45-
files = Dir.glob(File.join(my_fixture_dir, glob), flags)
46-
if files.empty?
47-
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!"
37+
# Return the contents of the file using read when given a name. Uses
38+
# my_fixture to work out the relative path.
39+
def my_fixture_read(name)
40+
File.read(my_fixture(name))
4841
end
4942

50-
block && files.each(&block)
51-
files
43+
# Provides a block mechanism for iterating across the files in your fixture
44+
# area.
45+
def my_fixtures(glob = '*', flags = 0, &block)
46+
files = Dir.glob(File.join(my_fixture_dir, glob), flags)
47+
if files.empty?
48+
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!"
49+
end
50+
51+
block && files.each(&block)
52+
files
53+
end
5254
end
5355
end

lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb

+34-32
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,43 @@
44
# 'puppetlabs_spec_helper/puppet_spec_helper' library
55
require 'puppetlabs_spec_helper/puppet_spec_helper'
66

7-
# PuppetInternals provides a set of methods that interface
8-
# with internal puppet implementations.
9-
module PuppetlabsSpec::PuppetInternals
10-
def resource(parts = {})
11-
resource_type = parts[:type] || :hostclass
12-
resource_name = parts[:name] || 'testing'
13-
Puppet::Resource::Type.new(resource_type, resource_name)
14-
end
15-
module_function :resource
7+
module PuppetlabsSpec
8+
# PuppetInternals provides a set of methods that interface
9+
# with internal puppet implementations.
10+
module PuppetInternals
11+
def resource(parts = {})
12+
resource_type = parts[:type] || :hostclass
13+
resource_name = parts[:name] || 'testing'
14+
Puppet::Resource::Type.new(resource_type, resource_name)
15+
end
16+
module_function :resource
1617

17-
def compiler(parts = {})
18-
compiler_node = parts[:node] || node
19-
Puppet::Parser::Compiler.new(compiler_node)
20-
end
21-
module_function :compiler
18+
def compiler(parts = {})
19+
compiler_node = parts[:node] || node
20+
Puppet::Parser::Compiler.new(compiler_node)
21+
end
22+
module_function :compiler
2223

23-
def node(parts = {})
24-
node_name = parts[:name] || 'testinghost'
25-
options = parts[:options] || {}
26-
node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', [])
27-
options[:environment] = node_environment
28-
Puppet::Node.new(node_name, options)
29-
end
30-
module_function :node
24+
def node(parts = {})
25+
node_name = parts[:name] || 'testinghost'
26+
options = parts[:options] || {}
27+
node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', [])
28+
options[:environment] = node_environment
29+
Puppet::Node.new(node_name, options)
30+
end
31+
module_function :node
3132

32-
# Return a method instance for a given function. This is primarily useful
33-
# for rspec-puppet
34-
def function_method(name, parts = {})
35-
scope = parts[:scope] || scope()
36-
# Ensure the method instance is defined by side-effect of checking if it
37-
# exists. This is a hack, but at least it's a hidden hack and not an
38-
# exposed hack.
39-
return nil unless Puppet::Parser::Functions.function(name)
33+
# Return a method instance for a given function. This is primarily useful
34+
# for rspec-puppet
35+
def function_method(name, parts = {})
36+
scope = parts[:scope] || scope()
37+
# Ensure the method instance is defined by side-effect of checking if it
38+
# exists. This is a hack, but at least it's a hidden hack and not an
39+
# exposed hack.
40+
return nil unless Puppet::Parser::Functions.function(name)
4041

41-
scope.method("function_#{name}".to_sym)
42+
scope.method("function_#{name}".to_sym)
43+
end
44+
module_function :function_method
4245
end
43-
module_function :function_method
4446
end

lib/puppetlabs_spec_helper/tasks/check_symlinks.rb

+41-37
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,52 @@
22

33
require 'pathspec'
44

5-
# Helpers for validating symlinks.
6-
class PuppetlabsSpecHelper::Tasks::CheckSymlinks
7-
DEFAULT_IGNORED = [
8-
'/.git/',
9-
'/.bundle/',
10-
'/vendor/',
11-
].freeze
12-
13-
IGNORE_LIST_FILES = [
14-
'.pdkignore',
15-
'.gitignore',
16-
].freeze
17-
18-
def check(dir = Dir.pwd)
19-
dir = Pathname.new(dir) unless dir.is_a?(Pathname)
20-
results = []
21-
22-
dir.each_child(true) do |child|
23-
next if ignored?(child.to_s)
24-
25-
if child.symlink?
26-
results << child
27-
elsif child.directory? && child.basename.to_s !~ %r{^(\.git|\.?bundle)$}
28-
results.concat(check(child))
5+
module PuppetlabsSpecHelper
6+
module Tasks
7+
# Helpers for validating symlinks.
8+
class CheckSymlinks
9+
DEFAULT_IGNORED = [
10+
'/.git/',
11+
'/.bundle/',
12+
'/vendor/',
13+
].freeze
14+
15+
IGNORE_LIST_FILES = [
16+
'.pdkignore',
17+
'.gitignore',
18+
].freeze
19+
20+
def check(dir = Dir.pwd)
21+
dir = Pathname.new(dir) unless dir.is_a?(Pathname)
22+
results = []
23+
24+
dir.each_child(true) do |child|
25+
next if ignored?(child.to_s)
26+
27+
if child.symlink?
28+
results << child
29+
elsif child.directory? && child.basename.to_s !~ %r{^(\.git|\.?bundle)$}
30+
results.concat(check(child))
31+
end
32+
end
33+
34+
results
2935
end
30-
end
31-
32-
results
33-
end
3436

35-
def ignored?(path)
36-
path = "#{path}/" if File.directory?(path)
37+
def ignored?(path)
38+
path = "#{path}/" if File.directory?(path)
3739

38-
!ignore_pathspec.match_paths([path], Dir.pwd).empty?
39-
end
40+
!ignore_pathspec.match_paths([path], Dir.pwd).empty?
41+
end
4042

41-
def ignore_pathspec
42-
@ignore_pathspec ||= PathSpec.new(DEFAULT_IGNORED).tap do |pathspec|
43-
IGNORE_LIST_FILES.each do |f|
44-
next unless File.file?(f) && File.readable?(f)
43+
def ignore_pathspec
44+
@ignore_pathspec ||= PathSpec.new(DEFAULT_IGNORED).tap do |pathspec|
45+
IGNORE_LIST_FILES.each do |f|
46+
next unless File.file?(f) && File.readable?(f)
4547

46-
File.open(f, 'r') { |fd| pathspec.add(fd) }
48+
File.open(f, 'r') { |fd| pathspec.add(fd) }
49+
end
50+
end
4751
end
4852
end
4953
end

0 commit comments

Comments
 (0)