Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .noexec.yaml

This file was deleted.

24 changes: 5 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,17 @@ A number of the Puppet parser features, controlled via configuration during a
normal puppet run, can be controlled by exporting specific environment
variables for the spec run. These are:

* ``STRICT_VARIABLES`` - set to "yes" to enable set to strict variable checking when using Puppet versions between 3.5 and 4.0;
set to "no" to disable strict variable checking on Puppet versions 4.0, and later.
See [strict_variables](http://docs.puppetlabs.com/references/latest/configuration.html#strictvariables)
in puppet.conf for details.
* ``STRICT_VARIABLES`` - Set to "no" to disable strict variable checking.
See [strict_variables](http://docs.puppetlabs.com/references/latest/configuration.html#strictvariables) in puppet.conf for details.
* ``ORDERING`` - set to the desired ordering method ("title-hash", "manifest", or "random")
to set the order of unrelated resources when applying a catalog. Leave unset for the default
behavior, currently "random". This is equivalent to setting [ordering](http://docs.puppetlabs.com/references/latest/configuration.html#ordering)
in puppet.conf.
* The following options only affect Puppet 3.x:
* ``FUTURE_PARSER`` _(Puppet 3.x, starting with 3.2)_ - set to "yes" to enable the [future parser](https://docs.puppet.com/puppet/3/experiments_future.html),
the equivalent of setting [parser=future](https://puppet.com/docs/puppet/3.8/configuration.html#parser)
in puppet.conf.
* ``TRUSTED_NODE_DATA`` _(Puppet 3.x, starting with 3.4)_ - set to "yes" to enable [the $facts hash and trusted node data](https://puppet.com/docs/puppet/3.8/lang_facts_and_builtin_vars.html#trusted-facts),
which enabled ``$facts`` and ``$trusted`` hashes. This is equivalent to setting
[trusted_node_data=true](https://puppet.com/docs/puppet/3.8/configuration.html#trustednodedata)
in puppet.conf.
* ``STRINGIFY_FACTS`` _(Puppet 3.x, starting with 3.5)_ - set to "no" to enable [structured facts](http://docs.puppetlabs.com/facter/2.0/fact_overview.html#writing-structured-facts),
otherwise leave unset to retain the current default behavior. This is equivalent to setting
[stringify_facts=false](https://puppet.com/docs/puppet/3.8/configuration.html#stringifyfacts)
in puppet.conf.

As an example, to run spec tests with the future parser, strict variable checking,

As an example, to run spec tests with the future parser, strict variable checking,
and manifest ordering, you would:

FUTURE_PARSER=yes STRICT_VARIABLES=yes ORDERING=manifest rake spec
ORDERING=manifest rake spec


Using Utility Classes
Expand Down
10 changes: 2 additions & 8 deletions lib/puppetlabs_spec_helper/module_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ def verify_contents(subject, title, expected_lines)
c.formatter = 'RSpec::Github::Formatter'
end

c.environmentpath = spec_path if Puppet.version.to_f >= 4.0
c.environmentpath = spec_path
c.module_path = module_path
c.manifest_dir = File.join(fixture_path, 'manifests')
c.parser = 'future' if ENV['FUTURE_PARSER'] == 'yes'

c.before :each do
if c.mock_framework.framework_name == :rspec
Expand All @@ -78,12 +77,7 @@ def verify_contents(subject, title, expected_lines)
Puppet.features.stubs(:root?).returns(true)
end

# stringify_facts and trusted_node_data were removed in puppet4
if Puppet.version.to_f < 4.0
Puppet.settings[:stringify_facts] = false if ENV['STRINGIFY_FACTS'] == 'no'
Puppet.settings[:trusted_node_data] = true if ENV['TRUSTED_NODE_DATA'] == 'yes'
end
Puppet.settings[:strict_variables] = true if ENV['STRICT_VARIABLES'] == 'yes' || (Puppet.version.to_f >= 4.0 && ENV['STRICT_VARIABLES'] != 'no')
Puppet.settings[:strict_variables] = true if ENV['STRICT_VARIABLES'] == 'yes' || ENV['STRICT_VARIABLES'] != 'no'
Puppet.settings[:ordering] = ENV['ORDERING'] if ENV['ORDERING']
end
end
87 changes: 1 addition & 86 deletions lib/puppetlabs_spec_helper/puppet_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,99 +51,14 @@
# Continue gracefully
end

# This is just a utility class to allow us to isolate the various version-specific
# branches of initialization logic into methods without polluting the global namespace.#
class Puppet::PuppetSpecInitializer
# This method is for initializing puppet state for testing for older versions
# of puppet that do not support the new TestHelper API. As you can see,
# this involves explicitly modifying global variables, directly manipulating
# Puppet's Settings singleton object, and other fun implementation details
# that code external to puppet should really never know about.
def self.initialize_via_fallback_compatibility(config)
warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
config.before :all do
# nothing to do for now
end

config.after :all do
# nothing to do for now
end

config.before :each do
# these globals are set by Application
$puppet_application_mode = nil # rubocop:disable Style/GlobalVars
$puppet_application_name = nil # rubocop:disable Style/GlobalVars

# REVISIT: I think this conceals other bad tests, but I don't have time to
# fully diagnose those right now. When you read this, please come tell me
# I suck for letting this float. --daniel 2011-04-21
Signal.stubs(:trap)

# Set the confdir and vardir to gibberish so that tests
# have to be correctly mocked.
Puppet[:confdir] = '/dev/null'
Puppet[:vardir] = '/dev/null'

# Avoid opening ports to the outside world
Puppet.settings[:bindaddress] = '127.0.0.1'
end

config.after :each do
Puppet.settings.clear

Puppet::Node::Environment.clear
Puppet::Util::Storage.clear
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'

PuppetlabsSpec::Files.cleanup
end
end
end

# JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534)
unless Puppet.constants.include? 'Test'
module Puppet::Test
# This is a stub class to allow the stdlib tests to run in Puppet 2.6
# This class will be removed in another commit.
class LogCollector
def initialize(logs)
@logs = logs
end

def <<(value)
@logs << value
end
end
end
Puppet::Util::Log.newdesttype :log_collector do
match 'Puppet::Test::LogCollector'

def initialize(messages)
@messages = messages
end

def handle(msg)
@messages << msg
end
end
end

# And here is where we do the main rspec configuration / setup.
RSpec.configure do |config|
# Detect whether the module is overriding the choice of mocking framework
# @mock_framework is used since more than seven years, and we need to avoid
# `mock_framework`'s autoloading to distinguish between the default, and
# the module's choice.
if config.instance_variable_get(:@mock_framework).nil?
RSpec.warn_deprecation('puppetlabs_spec_helper: defaults `mock_with` to `:mocha`. See https://github.com/puppetlabs/puppetlabs_spec_helper#mock_with to choose a sensible value for you')
config.mock_with :mocha
end

# determine whether we can use the new API or not, and call the appropriate initializer method.
if defined?(Puppet::Test::TestHelper)
# This case is handled by rspec-puppet since v1.0.0 (via 41257b33cb1f9ade4426b044f70be511b0c89112)
else
Puppet::PuppetSpecInitializer.initialize_via_fallback_compatibility(config)
config.mock_with :rspec
end

# Here we do some general setup that is relevant to all initialization modes, regardless
Expand Down
12 changes: 0 additions & 12 deletions lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
require 'stringio'
require 'rspec/expectations'

########################################################################
# Backward compatibility for Jenkins outdated environment.
module RSpec::Matchers::BlockAliases
if method_defined?(:should) && !method_defined?(:to)
alias to should
end
if method_defined? :should_not
alias to_not should_not unless method_defined? :to_not
alias not_to should_not unless method_defined? :not_to
end
end
########################################################################
# Custom matchers...
RSpec::Matchers.define :have_matching_element do |expected|
match do |actual|
Expand Down
34 changes: 1 addition & 33 deletions lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@
# PuppetInternals provides a set of methods that interface
# with internal puppet implementations.
module PuppetlabsSpec::PuppetInternals
# parser_scope is intended to return a Puppet::Parser::Scope
# instance suitable for placing in a test harness with the intent of
# testing parser functions from modules.
def scope(parts = {})
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')

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

scope_compiler = parts[:compiler] || compiler
scope_parent = parts[:parent] || scope_compiler.topscope

scope = if %r{^2\.[67]}.match?(Puppet.version)
Puppet::Parser::Scope.new(compiler: scope_compiler)
else
Puppet::Parser::Scope.new(scope_compiler)
end

scope.source = Puppet::Resource::Type.new(:node, 'foo')
scope.parent = scope_parent
scope
end
module_function :scope

def resource(parts = {})
resource_type = parts[:type] || :hostclass
resource_name = parts[:name] || 'testing'
Expand All @@ -51,11 +23,7 @@ def compiler(parts = {})
def node(parts = {})
node_name = parts[:name] || 'testinghost'
options = parts[:options] || {}
node_environment = if Puppet.version.to_f >= 4.0
Puppet::Node::Environment.create(parts[:environment] || 'test', [])
else
Puppet::Node::Environment.new(parts[:environment] || 'test')
end
node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', [])
options[:environment] = node_environment
Puppet::Node.new(node_name, options)
end
Expand Down
28 changes: 2 additions & 26 deletions lib/puppetlabs_spec_helper/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,10 @@

desc 'Build puppet module package'
task :build do
if Gem::Specification.find_by_name('puppet').version < Gem::Version.new('6.0.0')
Rake::Task['build:pmt'].invoke
else
Rake::Task['build:pdk'].invoke
end
Rake::Task['build:pdk'].invoke
end

namespace :build do
desc 'Build Puppet module package with PMT (Puppet < 6.0.0 only)'
task :pmt do
require 'puppet/face'

pmod = Puppet::Face['module', :current]
pmod.build('./')
end

desc 'Build Puppet module with PDK'
task :pdk do
require 'pdk/util'
Expand Down Expand Up @@ -204,9 +192,6 @@
PuppetSyntax.exclude_paths << 'vendor/**/*'
PuppetSyntax.exclude_paths << '.vendor/**/*'
PuppetSyntax.exclude_paths << 'plans/**/*'
if Puppet.version.to_f < 4.0
PuppetSyntax.exclude_paths << 'types/**/*'
end

desc 'Check syntax of Ruby files and call :syntax and :metadata_lint'
task :validate do
Expand All @@ -232,15 +217,6 @@
end
end

task :metadata do
warn "The 'metadata' task is deprecated. Please use 'metadata_lint' instead."
if Rake::Task.task_defined?(:metadata_lint)
Rake::Task[:metadata_lint].invoke
else
warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
end
end

desc 'Print development version of module'
task :compute_dev_version do
version = ''
Expand All @@ -263,7 +239,7 @@
# If the branch is a release branch we append an 'r' into the new_version,
# this is due to the release branch buildID conflicting with main branch when trying to push to the staging forge.
# More info can be found at https://tickets.puppetlabs.com/browse/FM-6170
new_version = if (build = (ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER']))
new_version = if (build = ENV['BUILD_NUMBER'])
if branch.eql? 'release'
'%s-%s%04d-%s' % [version, 'r', build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
else
Expand Down
5 changes: 0 additions & 5 deletions lib/puppetlabs_spec_helper/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

module PuppetlabsSpecHelper
VERSION = '4.0.1'

# compat for pre-1.2.0 users; deprecated
module Version
STRING = PuppetlabsSpecHelper::VERSION
end
end
7 changes: 0 additions & 7 deletions puppet_spec_helper.rb

This file was deleted.

4 changes: 3 additions & 1 deletion puppetlabs_spec_helper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ Gem::Specification.new do |spec|
spec.executables = Dir['bin/**/*'].map { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.required_ruby_version = Gem::Requirement.new('>= 2.7'.freeze)
spec.required_ruby_version = Gem::Requirement.new('>= 2.7')

spec.add_runtime_dependency 'mocha', '~> 1.0'
spec.add_runtime_dependency 'pathspec', '~> 1.0'
spec.add_runtime_dependency 'puppet-lint', '~> 3.0'
spec.add_runtime_dependency 'puppet-syntax', '~> 3.0'
spec.add_runtime_dependency 'rspec-github', '~> 2.0'
spec.add_runtime_dependency 'rspec-puppet', '~> 2.0'

spec.requirements << 'puppet, >= 6.0.0'
Comment on lines +29 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to the party, but AFAIK Puppet 6 doesn't run on Ruby 2.7. I'd expect either Ruby 2.5 + Puppet 6 or Ruby 2.7 + Puppet 7.

end
7 changes: 0 additions & 7 deletions puppetlabs_spec_helper.rb

This file was deleted.

1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def symlink?
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.mock_with :rspec

config.include_context 'with a rake task', type: :task
end
Loading