Skip to content

Commit 2677ac2

Browse files
committed
(CONT-237) Rubocop - updates for puppetlabs_spec
1 parent 84b0453 commit 2677ac2

File tree

4 files changed

+72
-76
lines changed

4 files changed

+72
-76
lines changed

lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# rubocop:disable Style/GlobalVars # TODO: investigate the use of instance variables
4+
35
require 'fileutils'
46
require 'tempfile'
57
require 'pathname'
@@ -20,7 +22,7 @@ def self.in_tmp(path)
2022

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

2628
begin

lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def fixtures(*rest)
1414
# <project>/spec/fixture/unit/facter/foo
1515
def my_fixture_dir
1616
callers = caller
17-
while line = callers.shift
18-
next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
17+
while (line = callers.shift)
18+
next unless (found = line.match(%r{/spec/(.*)_spec\.rb:}))
1919

2020
return fixtures(found[1])
2121
end
@@ -47,7 +47,7 @@ def my_fixtures(glob = '*', flags = 0, &block)
4747
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!"
4848
end
4949

50-
block_given? && files.each(&block)
50+
block && files.each(&block)
5151
files
5252
end
5353
end

lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55

66
########################################################################
77
# Backward compatibility for Jenkins outdated environment.
8-
module RSpec
9-
module Matchers
10-
module BlockAliases
11-
if method_defined?(:should) && !method_defined?(:to)
12-
alias to should
13-
end
14-
if method_defined? :should_not
15-
alias to_not should_not unless method_defined? :to_not
16-
alias not_to should_not unless method_defined? :not_to
17-
end
18-
end
8+
module RSpec::Matchers::BlockAliases
9+
if method_defined?(:should) && !method_defined?(:to)
10+
alias to should
11+
end
12+
if method_defined? :should_not
13+
alias to_not should_not unless method_defined? :to_not
14+
alias not_to should_not unless method_defined? :not_to
1915
end
2016
end
21-
2217
########################################################################
2318
# Custom matchers...
2419
RSpec::Matchers.define :have_matching_element do |expected|

lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,73 @@
44
# 'puppetlabs_spec_helper/puppet_spec_helper' library
55
require 'puppetlabs_spec_helper/puppet_spec_helper'
66

7-
module PuppetlabsSpec
8-
module PuppetInternals
9-
# parser_scope is intended to return a Puppet::Parser::Scope
10-
# instance suitable for placing in a test harness with the intent of
11-
# testing parser functions from modules.
12-
def scope(parts = {})
13-
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
7+
# PuppetInternals provides a set of methods that interface
8+
# with internal puppet implementations.
9+
module PuppetlabsSpec::PuppetInternals
10+
# parser_scope is intended to return a Puppet::Parser::Scope
11+
# instance suitable for placing in a test harness with the intent of
12+
# testing parser functions from modules.
13+
def scope(parts = {})
14+
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
1415

15-
if %r{^2\.[67]}.match?(Puppet.version)
16-
# loadall should only be necessary prior to 3.x
17-
# Please note, loadall needs to happen first when creating a scope, otherwise
18-
# you might receive undefined method `function_*' errors
19-
Puppet::Parser::Functions.autoloader.loadall
20-
end
16+
if %r{^2\.[67]}.match?(Puppet.version)
17+
# loadall should only be necessary prior to 3.x
18+
# Please note, loadall needs to happen first when creating a scope, otherwise
19+
# you might receive undefined method `function_*' errors
20+
Puppet::Parser::Functions.autoloader.loadall
21+
end
2122

22-
scope_compiler = parts[:compiler] || compiler
23-
scope_parent = parts[:parent] || scope_compiler.topscope
24-
scope_resource = parts[:resource] || resource(type: :node, title: scope_compiler.node.name)
23+
scope_compiler = parts[:compiler] || compiler
24+
scope_parent = parts[:parent] || scope_compiler.topscope
2525

26-
scope = if %r{^2\.[67]}.match?(Puppet.version)
27-
Puppet::Parser::Scope.new(compiler: scope_compiler)
28-
else
29-
Puppet::Parser::Scope.new(scope_compiler)
30-
end
26+
scope = if %r{^2\.[67]}.match?(Puppet.version)
27+
Puppet::Parser::Scope.new(compiler: scope_compiler)
28+
else
29+
Puppet::Parser::Scope.new(scope_compiler)
30+
end
3131

32-
scope.source = Puppet::Resource::Type.new(:node, 'foo')
33-
scope.parent = scope_parent
34-
scope
35-
end
36-
module_function :scope
32+
scope.source = Puppet::Resource::Type.new(:node, 'foo')
33+
scope.parent = scope_parent
34+
scope
35+
end
36+
module_function :scope
3737

38-
def resource(parts = {})
39-
resource_type = parts[:type] || :hostclass
40-
resource_name = parts[:name] || 'testing'
41-
Puppet::Resource::Type.new(resource_type, resource_name)
42-
end
43-
module_function :resource
38+
def resource(parts = {})
39+
resource_type = parts[:type] || :hostclass
40+
resource_name = parts[:name] || 'testing'
41+
Puppet::Resource::Type.new(resource_type, resource_name)
42+
end
43+
module_function :resource
4444

45-
def compiler(parts = {})
46-
compiler_node = parts[:node] || node
47-
Puppet::Parser::Compiler.new(compiler_node)
48-
end
49-
module_function :compiler
45+
def compiler(parts = {})
46+
compiler_node = parts[:node] || node
47+
Puppet::Parser::Compiler.new(compiler_node)
48+
end
49+
module_function :compiler
5050

51-
def node(parts = {})
52-
node_name = parts[:name] || 'testinghost'
53-
options = parts[:options] || {}
54-
node_environment = if Puppet.version.to_f >= 4.0
55-
Puppet::Node::Environment.create(parts[:environment] || 'test', [])
56-
else
57-
Puppet::Node::Environment.new(parts[:environment] || 'test')
58-
end
59-
options[:environment] = node_environment
60-
Puppet::Node.new(node_name, options)
61-
end
62-
module_function :node
51+
def node(parts = {})
52+
node_name = parts[:name] || 'testinghost'
53+
options = parts[:options] || {}
54+
node_environment = if Puppet.version.to_f >= 4.0
55+
Puppet::Node::Environment.create(parts[:environment] || 'test', [])
56+
else
57+
Puppet::Node::Environment.new(parts[:environment] || 'test')
58+
end
59+
options[:environment] = node_environment
60+
Puppet::Node.new(node_name, options)
61+
end
62+
module_function :node
6363

64-
# Return a method instance for a given function. This is primarily useful
65-
# for rspec-puppet
66-
def function_method(name, parts = {})
67-
scope = parts[:scope] || scope()
68-
# Ensure the method instance is defined by side-effect of checking if it
69-
# exists. This is a hack, but at least it's a hidden hack and not an
70-
# exposed hack.
71-
return nil unless Puppet::Parser::Functions.function(name)
64+
# Return a method instance for a given function. This is primarily useful
65+
# for rspec-puppet
66+
def function_method(name, parts = {})
67+
scope = parts[:scope] || scope()
68+
# Ensure the method instance is defined by side-effect of checking if it
69+
# exists. This is a hack, but at least it's a hidden hack and not an
70+
# exposed hack.
71+
return nil unless Puppet::Parser::Functions.function(name)
7272

73-
scope.method("function_#{name}".intern)
74-
end
75-
module_function :function_method
73+
scope.method("function_#{name}".to_sym)
7674
end
75+
module_function :function_method
7776
end

0 commit comments

Comments
 (0)