[DRE-commits] [ruby-puppetlabs-spec-helper] 01/05: Imported Upstream version 0.10.3
Gaudenz Steinlin
gaudenz at moszumanska.debian.org
Thu Oct 8 15:38:25 UTC 2015
This is an automated email from the git hooks/post-receive script.
gaudenz pushed a commit to branch master
in repository ruby-puppetlabs-spec-helper.
commit d962c4b8aedf7ed4d5ecee34c336fa466f586b06
Author: Gaudenz Steinlin <gaudenz at debian.org>
Date: Thu Oct 8 17:26:31 2015 +0200
Imported Upstream version 0.10.3
---
.gitignore | 3 +
.noexec.yaml | 4 +
CHANGELOG | 27 ---
CHANGELOG.md | 215 +++++++++++++++++++
Gemfile | 9 +
README.markdown | 231 +++++++++++++++++++++
Rakefile | 33 +++
lib/puppetlabs_spec_helper/module_spec_helper.rb | 22 +-
lib/puppetlabs_spec_helper/puppet_spec_helper.rb | 1 -
.../puppetlabs_spec/matchers.rb | 11 +-
.../puppetlabs_spec/puppet_internals.rb | 6 +-
lib/puppetlabs_spec_helper/rake_tasks.rb | 159 ++++++++++++--
lib/puppetlabs_spec_helper/version.rb | 5 +
metadata.yml | 211 ++++++++++---------
puppet_spec_helper.rb | 5 +
puppetlabs_spec_helper.gemspec | 25 +++
puppetlabs_spec_helper.rb | 5 +
spec/lib/puppet/type/spechelper.rb | 6 +
.../puppetlabs_spec/puppet_internals_spec.rb | 92 ++++++++
spec/unit/spechelper_spec.rb | 43 ++++
spec/watchr.rb | 79 +++++++
21 files changed, 1042 insertions(+), 150 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8558473
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+Gemfile.lock
+pkg/
+.*.sw*
diff --git a/.noexec.yaml b/.noexec.yaml
new file mode 100644
index 0000000..dd4203d
--- /dev/null
+++ b/.noexec.yaml
@@ -0,0 +1,4 @@
+---
+exclude:
+ - rake
+ - rspec
diff --git a/CHANGELOG b/CHANGELOG
deleted file mode 100644
index fe0627c..0000000
--- a/CHANGELOG
+++ /dev/null
@@ -1,27 +0,0 @@
-2013-02-08 Puppet Labs <info at puppetlabs.com> - 0.4.1
- * (#18165) Mark tests pending on broken puppet versions
- * (#18165) Initialize TestHelper as soon as possible
- * Maint: Change formatting and handle windows path separator
-
-2012-12-14 Puppet Labs <info at puppetlabs.com> - 0.4.0
- * Rake should fail if git can't clone repository
- * Add readme for fixtures
- * Fix Mocha deprecations
- * add opts logic to rake spec_clean
- * add backwards-compatible support for arbitrary git refs in .fixtures.yml
- * Only remove the site.pp if it is empty
- * (#15464) Make contributing easy via bundle Gemfile
- * (#15464) Add gemspec from 0.3.0 published gem
-
-2012-08-14 Puppet Labs <info at puppetlabs.com> - 0.3.0
- * Add PuppetInternals compatibility module for
- scope, node, compiler, and functions
- * Add rspec-puppet convention directories to rake tasks
-
-2012-07-05 Puppet Labs <info at puppetlabs.com> - 0.2.0
- * Fix integration with mocha-0.12.0
- * Fix coverage rake task
- * Fix an issue creating the fixtures directory
-
-2012-06-08 Puppet Labs <info at puppetlabs.com> - 0.1.0
- * Initial release
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..e14ea40
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,215 @@
+# Change log
+All notable changes to this project will be documented in this file.
+This project adheres to [Semantic Versioning](http://semver.org/).
+
+## [0.10.3] - 2015-05-11
+### Summary:
+A bugfix for puppet 3 and puppet 4 tests being able to run with the same environment variables.
+
+### Fixed:
+- Allow `STRINGIFY_FACTS` and `TRUSTED_NODE_DATA` to be set on Puppet 4 as noop instead of fail
+- Fix linting to be more like approved module criteria
+
+## [0.10.2] - 2015-04-14
+### Summary:
+A bugfix for puppet 4 coming out, which manages modulepath and environments differently.
+
+### Fixed:
+- Use puppet 4 environmentpath and environment creation on puppet 4
+
+## [0.10.1] - 2015-03-17
+### Summary:
+A bugfix for the previous release when using references.
+
+### Fixed:
+- Only shallow clone if not using a reference
+
+## [0.10.0] - 2015-03-16
+### Summary:
+This release adds shallow fixtures clones to speed up the spec_prep step for
+rspec-puppet
+
+### Added:
+- Shallow clone fixtures
+
+### Fixed:
+- Don't lint in vendor/ (spec/fixtures/ and pkg/ are alread ignored)
+- Don't syntax check in spec/fixtures/, pkg/, or vendor/
+
+## [0.9.1] - 2015-02-24
+### Summary:
+This release removes the hard dependency on metadata-json-lint, as it requires
+a dev toolchain to install the 'json' gem.
+
+### Fixed:
+- Only warn when metadata-json-lint isn't installed instead of requiring it
+
+## [0.9.0] - 2015-02-24
+### Summary:
+This release adds fixes for rspec-puppet 2.0 and json linting for metadata.json
+
+### Added:
+- Add json linting for metadata.json (adds dep on metadata-json-lint gem)
+- Document using references in fixtures
+
+### Fixed:
+- `FUTURE_PARSER=yes` working with rspec-puppet 2.0
+- Symlinks breaking on windows
+- rspec as a runtime dependency conflicting with rspec-puppet
+- root stub for testing execs
+
+## [0.8.2] - 2014-10-01
+### Summary:
+This release fixes the lint task on the latest puppet-lint
+
+### Fixed:
+- Fix the lint task require code
+
+## [0.8.1] - 2014-08-25
+### Summary:
+This release corrects compatibility with the recently-released puppet-lint
+1.0.0
+
+### Fixed:
+- Turn on relative autoloader lint checking for backwards-compatibility
+- Turn off param class inheritance check (deprecated style)
+- Fix ignore paths to ignore `pkg/*`
+
+## [0.8.0] - 2014-07-29
+### Summary:
+This release uses the new puppet-syntax gem to perform manifest validation
+better than before! Shiny.
+
+### Added:
+- Use puppet-syntax gem for manifest validation rake task
+
+### Fixed:
+- Fix compatibility with rspec 3
+
+## [0.7.0] - 2014-07-17
+### Summary:
+This feature release adds the ability to test structured facts, manifest
+ordering, and trusted node facts, and check out branches with fixtures.
+
+### Added:
+- Add `STRINGIFY_FACTS=no` for structured facts
+- Add `TRUSTED_NODE_DATA=yes` for trusted node data
+- Add `ORDERING=<order>` for manifest ordering
+- Add `:branch` support for fixtures on a branch.
+
+### Fixed:
+- Fix puppet-lint to ignore spec/fixtures/
+
+## [0.6.0] - 2014-07-02
+### Summary:
+This feature release adds the `validate` rake task and the ability to test
+strict variables and the future parser with rspec-puppet.
+
+### Added:
+- Add `validate` rake task.
+- Add `STRICT_VARIABLES=yes` to module_spec_helper
+- Add `FUTURE_PARSER=yes` to module_spec_helper
+
+### Fixed:
+- Avoid conflict with Object.clone
+- Install forge fixtures without conflicting with already-installed modules
+
+## [0.5.2] - 2014-06-19
+### Summary:
+This release removes the previously non-existant puppet runtime dependency to
+better match rspec-puppet and puppet-lint and allow system puppet packages to
+be used instead of gems.
+
+### Fixed:
+- Remove puppet dependency from gemspec
+
+## [0.5.1] - 2014-06-09
+### Summary:
+This release re-adds mocha mocking, which was mistakenly removed in 0.5.0
+
+### Fixed:
+- Re-enable mocha mocking as default.
+
+## [0.5.0] - 2014-06-06
+### Summary:
+This is the first feature release in over a year. The biggest feature is fixtures supporting the forge, and not just github, plus rake tasks for syntax checking and beaker.
+
+### Added:
+- Install modules from the forge, not just git
+- Beaker rake tasks added
+- Syntax task added
+- Rake spec runs tests in `integration/` directory
+
+### Fixed:
+- Fix the gemspec so that this may be used with bundler
+- Fix removal of symlinks
+- Fix removal of site.pp only when empty
+- Ignore fixtures for linting
+- Remove extra mocha dependency
+- Remove rspec pinning (oops)
+
+## 0.4.2 - 2014-06-06 [YANKED]
+### Summary:
+This release corrects the pinning of rspec for modules which are not rspec 3
+compatible yet.
+
+### Fixed:
+* Pin to 2.x range for rspec 2
+* Fix aborting rake task when packaging gem
+* Fix puppet issue tracker url
+* Fix issue with running `git reset` in the incorrect dir
+
+## [0.4.1] - 2013-02-08
+### Fixed
+ * (#18165) Mark tests pending on broken puppet versions
+ * (#18165) Initialize TestHelper as soon as possible
+ * Maint: Change formatting and handle windows path separator
+
+## [0.4.0] - 2012-12-14
+### Added
+ * Add readme for fixtures
+ * add opts logic to rake spec_clean
+ * add backwards-compatible support for arbitrary git refs in .fixtures.yml
+
+### Fixed
+ * Rake should fail if git can't clone repository
+ * Fix Mocha deprecations
+ * Only remove the site.pp if it is empty
+ * (#15464) Make contributing easy via bundle Gemfile
+ * (#15464) Add gemspec from 0.3.0 published gem
+
+## [0.3.0] - 2012-08-14
+### Added
+ * Add PuppetInternals compatibility module for
+ scope, node, compiler, and functions
+ * Add rspec-puppet convention directories to rake tasks
+
+## [0.2.0] - 2012-07-05
+### Fixed
+ * Fix integration with mocha-0.12.0
+ * Fix coverage rake task
+ * Fix an issue creating the fixtures directory
+
+## 0.1.0 - 2012-06-08
+### Added
+ * Initial release
+
+[unreleased]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.10.1...master
+[0.10.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.10.1...0.10.2
+[0.10.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.10.0...0.10.1
+[0.10.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.9.1...0.10.0
+[0.9.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.9.0...0.9.1
+[0.9.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.8.2...0.9.0
+[0.8.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.8.1...0.8.2
+[0.8.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.8.0...0.8.1
+[0.8.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.7.0...0.8.0
+[0.7.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.6.0...0.7.0
+[0.6.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.5.2...0.6.0
+[0.5.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.5.1...0.5.2
+[0.5.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.5.0...0.5.1
+[0.5.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.4.1...0.5.0
+[0.4.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.4.0...0.4.1
+[0.4.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.3.0...0.4.0
+[0.3.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.2.0...0.3.0
+[0.2.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.1.0...0.2.0
+[0.1.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.0.0...0.1.0
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..b14cb87
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,9 @@
+source :rubygems
+
+gemspec
+
+if File.exists? "#{__FILE__}.local"
+ eval(File.read("#{__FILE__}.local"), binding)
+end
+
+# vim:filetype=ruby
diff --git a/README.markdown b/README.markdown
new file mode 100644
index 0000000..8557f26
--- /dev/null
+++ b/README.markdown
@@ -0,0 +1,231 @@
+Puppet Labs Spec Helper
+=======================
+
+The Short Version
+-----------------
+
+This repository is meant to provide a single source of truth for how to
+initialize different Puppet versions for spec testing.
+
+The common use case is a module such as
+[stdlib](http://forge.puppetlabs.com/puppetlabs/stdlib) that works with many
+versions of Puppet. The stdlib module should require the spec helper in this
+repository, which will in turn automatically figure out the version of Puppet
+being tested against and perform version specific initialization.
+
+Other "customers" that should use this module are:
+
+ * [Facter](https://github.com/puppetlabs/facter)
+ * [PuppetDB](https://github.com/puppetlabs/puppetdb)
+ * [Mount Providers](https://github.com/puppetlabs/puppetlabs-mount_providers)
+
+Usage
+=====
+
+When developing or testing modules, simply clone this repository and install the
+gem it contains.
+
+ $ git clone git://github.com/puppetlabs/puppetlabs_spec_helper.git
+ $ cd puppetlabs_spec_helper
+ $ rake package:gem
+ $ gem install pkg/puppetlabs_spec_helper-*.gem
+
+Add this to your project's spec\_helper.rb:
+
+ require 'puppetlabs_spec_helper/module_spec_helper'
+
+Add this to your project's Rakefile:
+
+ require 'puppetlabs_spec_helper/rake_tasks'
+
+And run the spec tests:
+
+ $ cd $modulename
+ $ rake spec
+
+Issues
+======
+
+Please file issues against this project at the [Puppet Labs Issue
+Tracker](https://tickets.puppetlabs.com/browse/MODULES)
+
+The Long Version
+----------------
+
+Purpose of this Project
+=======================
+
+This project is intended to serve two purposes:
+
+1. To serve as a bridge between external projects and multiple versions of puppet;
+ in other words, if your project has a dependency on puppet, you shouldn't need
+ to need to worry about the details of how to initialize puppet's state for
+ testing, no matter what version of puppet you are testing against.
+2. To provide some convenience classes / methods for doing things like creating
+ tempfiles, common rspec matchers, etc. These classes are in the puppetlabs\_spec
+ directory.
+3. To provide a common set of Rake tasks so that the procedure for testing modules
+ is unified.
+
+To Use this Project
+===================
+
+The most common usage scenario is that you will check out the 'master'
+branch of this project from github, and install it as a rubygem.
+There should be few or no cases where you would want to have any other
+branch of this project besides master/HEAD.
+
+Initializing Puppet for Testing
+===============================
+
+In most cases, your project should be able to define a spec\_helper.rb that includes
+just this one simple line:
+
+ require 'puppetlabs_spec_helper/puppet_spec_helper'
+
+Then, as long as the gem is installed, you should be all set.
+
+If you are using rspec-puppet for module testing, you will want to include a different
+library:
+
+ require 'puppetlabs_spec_helper/module_spec_helper'
+
+NOTE that this is specifically for initializing Puppet's core. If your project does
+not have any dependencies on puppet and you just want to use the utility classes,
+see the next section.
+
+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:
+
+* ``FUTURE_PARSER`` - set to "yes" to enable the [future parser](http://docs.puppetlabs.com/puppet/latest/reference/experiments_future.html),
+ the equivalent of setting [parser=future](http://docs.puppetlabs.com/references/latest/configuration.html#parser)
+ in puppet.conf.
+* ``STRICT_VARIABLES`` - set to "yes" to enable strict variable checking,
+ the equivalent of setting [strict_variables](http://docs.puppetlabs.com/references/latest/configuration.html#strictvariables)=true
+ in puppet.conf.
+* ``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.
+* ``STRINGIFY_FACTS`` - 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](http://docs.puppetlabs.com/references/latest/configuration.html#stringifyfacts)
+ in puppet.conf.
+* ``TRUSTED_NODE_DATA`` - set to "yes" to enable [the $facts hash and trusted node data](http://docs.puppetlabs.com/puppet/latest/reference/lang_facts_and_builtin_vars.html),
+ which enabled ``$facts`` and ``$trusted`` hashes. This is equivalent to setting
+ [trusted_node_data=true](http://docs.puppetlabs.com/references/latest/configuration.html#trustednodedata)
+ in puppet.conf.
+
+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
+
+Using Utility Classes
+=====================
+If you'd like to use the Utility classes (PuppetlabsSpec::Files,
+PuppetlabsSpec::Fixtures), you just need to add this to your project's spec\_helper.rb:
+
+ require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
+
+NOTE that the above line happens automatically if you've required
+'puppetlabs\_spec\_helper/puppet\_spec\_helper', so you don't need to do both.
+
+In either case, you'll have all of the functionality of Puppetlabs::Files,
+Puppetlabs::Fixtures, etc., mixed-in to your rspec context.
+
+Using Fixtures
+==============
+`puppetlabs_spec_helper` has the ability to populate the
+`spec/fixtures/modules` directory with dependent modules when `rake spec` or
+`rake spec_prep` is run. To do so, all required modules should be listed in a
+file named `.fixtures.yml` in the root of the project.
+
+When specifying the repo source of the fixture you have a few options as to which revision of the codebase you wish to use.
+
+ * repo - the url to the repo
+ * scm - options include git or hg. This is an optional step as the helper code will figure out which scm is used.
+ ```yaml
+ scm: git
+ scm: hg
+ ```
+ * target - the directory name to clone the repo into ie. `target: mymodule` defaults to the repo name (Optional)
+ * ref - used to specify the tag name like version hash of commit (Optional)
+ ```yaml
+ ref: 1.0.0
+ ref: 880fca52c
+ ```
+ * branch - used to specify the branch name you want to use ie. `branch: development`
+
+ **Note:** ref and branch can be used together to get a specific revision on a specific branch
+
+Fixtures Examples
+-----------------
+Basic fixtures that will symlink `spec/fixtures/modules/my_modules` to the
+project root:
+
+ fixtures:
+ symlinks:
+ my_module: "#{source_dir}"
+
+
+Add `firewall` and `stdlib` as required module fixtures:
+
+ fixtures:
+ repositories:
+ firewall: "git://github.com/puppetlabs/puppetlabs-firewall"
+ stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib"
+ symlinks:
+ my_module: "#{source_dir}"
+
+Specify that the git tag `2.4.2` of `stdlib' should be checked out:
+
+ fixtures:
+ repositories:
+ firewall: "git://github.com/puppetlabs/puppetlabs-firewall"
+ stdlib:
+ repo: "git://github.com/puppetlabs/puppetlabs-stdlib"
+ ref: "2.6.0"
+ symlinks:
+ my_module: "#{source_dir}"
+
+Install modules from Puppet Forge:
+
+ fixtures:
+ forge_modules:
+ firewall: "puppetlabs/firewall"
+ stdlib:
+ repo: "puppetlabs/stdlib"
+ ref: "2.6.0"
+
+
+Testing Parser Functions
+========================
+
+This library provides a consistent way to create a Puppet::Parser::Scope object
+suitable for use in a testing harness with the intent of testing the expected
+behavior of parser functions distributed in modules.
+
+Previously, modules would do something like this:
+
+ describe "split()" do
+ let(:scope) { Puppet::Parser::Scope.new }
+ it "should split 'one;two' on ';' into [ 'one', 'two' ]" do
+ scope.function_split(['one;two', ';']).should == [ 'one', 'two' ]
+ end
+ end
+
+This will not work beyond Puppet 2.7 as we have changed the behavior of the
+scope initializer in Puppet 3.0. Modules should instead initialize scope
+instances in a manner decoupled from the internal behavior of Puppet:
+
+ require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
+ describe "split()" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should split 'one;two' on ';' into [ 'one', 'two' ]" do
+ scope.function_split(['one;two', ';']).should == [ 'one', 'two' ]
+ end
+ end
+
+EOF
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..9d27b23
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,33 @@
+require 'rake'
+require 'rake/packagetask'
+require 'rubygems/package_task'
+
+task :default do
+ sh %{rake -T}
+end
+
+require 'fileutils'
+
+def version
+ require 'puppetlabs_spec_helper/version'
+ PuppetlabsSpecHelper::Version::STRING
+end
+
+namespace :package do
+ desc "Create the gem"
+ task :gem do
+ spec = Gem::Specification.load("puppetlabs_spec_helper.gemspec")
+ Dir.mkdir("pkg") rescue nil
+ if Gem::Version.new(`gem -v`) >= Gem::Version.new("2.0.0.a")
+ Gem::Package.build(spec)
+ else
+ Gem::Builder.new(spec).build
+ end
+ FileUtils.move("puppetlabs_spec_helper-#{version}.gem", "pkg")
+ end
+end
+
+desc "Cleanup pkg directory"
+task :clean do
+ FileUtils.rm_rf("pkg")
+end
diff --git a/lib/puppetlabs_spec_helper/module_spec_helper.rb b/lib/puppetlabs_spec_helper/module_spec_helper.rb
index 286f374..3efcd71 100644
--- a/lib/puppetlabs_spec_helper/module_spec_helper.rb
+++ b/lib/puppetlabs_spec_helper/module_spec_helper.rb
@@ -11,7 +11,8 @@ def verify_contents(subject, title, expected_lines)
(content.split("\n") & expected_lines).should == expected_lines
end
-fixture_path = File.expand_path(File.join(Dir.pwd, 'spec/fixtures'))
+spec_path = File.expand_path(File.join(Dir.pwd, 'spec'))
+fixture_path = File.join(spec_path, 'fixtures')
env_module_path = ENV['MODULEPATH']
module_path = File.join(fixture_path, 'modules')
@@ -19,6 +20,25 @@ module_path = File.join(fixture_path, 'modules')
module_path = [module_path, env_module_path].join(File::PATH_SEPARATOR) if env_module_path
RSpec.configure do |c|
+ c.environmentpath = spec_path if Puppet.version.to_f >= 4.0
c.module_path = module_path
c.manifest_dir = File.join(fixture_path, 'manifests')
+ c.parser = 'future' if ENV['FUTURE_PARSER'] == 'yes'
+ ## This depends on rspec-puppet #209 being released
+ #c.strict_variables = true if ENV['STRICT_VARIABLES'] == 'yes'
+ ## These depend on rspec-puppet #212 being released
+ #c.stringify_facts = false if ENV['STRINGIFY_FACTS'] == 'no'
+ #c.trusted_node_data = true if ENV['TRUSTED_NODE_DATA'] == 'yes'
+ #c.ordering = ENV['ORDERING'] if ENV['ORDERING']
+
+ c.before :each do
+ Puppet.features.stubs(:root?).returns(true)
+ # 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.settings[:ordering] = ENV['ORDERING'] if ENV['ORDERING']
+ end
end
diff --git a/lib/puppetlabs_spec_helper/puppet_spec_helper.rb b/lib/puppetlabs_spec_helper/puppet_spec_helper.rb
index 9fb92f9..f65c113 100644
--- a/lib/puppetlabs_spec_helper/puppet_spec_helper.rb
+++ b/lib/puppetlabs_spec_helper/puppet_spec_helper.rb
@@ -7,7 +7,6 @@ ARGV.clear
ENV['MOCHA_OPTIONS']='skip_integration'
require 'puppet'
-gem 'rspec', '>=2.0.0'
require 'rspec/expectations'
require 'mocha/api'
diff --git a/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb b/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb
index 77f5803..5353388 100644
--- a/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb
+++ b/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb
@@ -1,13 +1,18 @@
require 'stringio'
+require 'rspec/expectations'
########################################################################
# Backward compatibility for Jenkins outdated environment.
module RSpec
module Matchers
module BlockAliases
- alias_method :to, :should unless method_defined? :to
- alias_method :to_not, :should_not unless method_defined? :to_not
- alias_method :not_to, :should_not unless method_defined? :not_to
+ if method_defined? :should
+ alias_method :to, :should unless method_defined? :to
+ end
+ if method_defined? :should_not
+ alias_method :to_not, :should_not unless method_defined? :to_not
+ alias_method :not_to, :should_not unless method_defined? :not_to
+ end
end
end
end
diff --git a/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb b/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
index bb62fa9..f51bd72 100644
--- a/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
+++ b/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
@@ -47,7 +47,11 @@ module PuppetlabsSpec
def node(parts = {})
node_name = parts[:name] || 'testinghost'
options = parts[:options] || {}
- node_environment = Puppet::Node::Environment.new(parts[:environment] || 'test')
+ if Puppet.version.to_f >= 4.0
+ node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', [])
+ else
+ node_environment = Puppet::Node::Environment.new(parts[:environment] || 'test')
+ end
options.merge!({:environment => node_environment})
Puppet::Node.new(node_name, options)
end
diff --git a/lib/puppetlabs_spec_helper/rake_tasks.rb b/lib/puppetlabs_spec_helper/rake_tasks.rb
index 99f8ea2..db15bea 100644
--- a/lib/puppetlabs_spec_helper/rake_tasks.rb
+++ b/lib/puppetlabs_spec_helper/rake_tasks.rb
@@ -7,7 +7,13 @@ task :default => [:help]
desc "Run spec tests on an existing fixtures directory"
RSpec::Core::RakeTask.new(:spec_standalone) do |t|
t.rspec_opts = ['--color']
- t.pattern = 'spec/{classes,defines,unit,functions,hosts}/**/*_spec.rb'
+ t.pattern = 'spec/{classes,defines,unit,functions,hosts,integration}/**/*_spec.rb'
+end
+
+desc "Run beaker acceptance tests"
+RSpec::Core::RakeTask.new(:beaker) do |t|
+ t.rspec_opts = ['--color']
+ t.pattern = 'spec/acceptance'
end
desc "Generate code coverage information"
@@ -33,7 +39,7 @@ def fixtures(category)
end
result = {}
- if fixtures.include? category
+ if fixtures.include? category and fixtures[category] != nil
fixtures[category].each do |fixture, opts|
if opts.instance_of?(String)
source = opts
@@ -43,33 +49,99 @@ def fixtures(category)
elsif opts.instance_of?(Hash)
target = "spec/fixtures/modules/#{fixture}"
real_source = eval('"'+opts["repo"]+'"')
- result[real_source] = { "target" => target, "ref" => opts["ref"] }
+ result[real_source] = { "target" => target, "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"] }
end
end
end
return result
end
+def clone_repo(scm, remote, target, ref=nil, branch=nil)
+ args = []
+ case scm
+ when 'hg'
+ args.push('clone')
+ args.push('-u', ref) if ref
+ args.push(remote, target)
+ when 'git'
+ args.push('clone')
+ args.push('--depth 1') unless ref
+ args.push('-b', branch) if branch
+ args.push(remote, target)
+ else
+ fail "Unfortunately #{scm} is not supported yet"
+ end
+ system("#{scm} #{args.flatten.join ' '}")
+end
+
+def revision(scm, target, ref)
+ args = []
+ case scm
+ when 'hg'
+ args.push('update', 'clean', '-r', ref)
+ when 'git'
+ args.push('reset', '--hard', ref)
+ else
+ fail "Unfortunately #{scm} is not supported yet"
+ end
+ system("cd #{target} && #{scm} #{args.flatten.join ' '}")
+end
+
desc "Create the fixtures directory"
task :spec_prep do
+ # Ruby only sets File::ALT_SEPARATOR on Windows and Rubys standard library
+ # uses this to check for Windows
+ is_windows = !!File::ALT_SEPARATOR
+ puppet_symlink_available = false
+ begin
+ require 'puppet'
+ puppet_symlink_available = Puppet::FileSystem.respond_to?(:symlink)
+ rescue
+ end
+
+
fixtures("repositories").each do |remote, opts|
+ scm = 'git'
if opts.instance_of?(String)
target = opts
- ref = "refs/remotes/origin/master"
elsif opts.instance_of?(Hash)
target = opts["target"]
ref = opts["ref"]
+ scm = opts["scm"] if opts["scm"]
+ branch = opts["branch"] if opts["branch"]
end
- unless File::exists?(target) || system("git clone #{remote} #{target}")
- fail "Failed to clone #{remote} into #{target}"
+ unless File::exists?(target) || clone_repo(scm, remote, target, ref, branch)
+ fail "Failed to clone #{scm} repository #{remote} into #{target}"
end
- system("cd #{target}; git reset --hard #{ref}") if ref
+ revision(scm, target, ref) if ref
end
FileUtils::mkdir_p("spec/fixtures/modules")
fixtures("symlinks").each do |source, target|
- File::exists?(target) || FileUtils::ln_s(source, target)
+ if is_windows
+ fail "Cannot symlink on Windows unless using at least Puppet 3.5" if !puppet_symlink_available
+ Puppet::FileSystem::exist?(target) || Puppet::FileSystem::symlink(source, target)
+ else
+ File::exists?(target) || FileUtils::ln_sf(source, target)
+ end
+ end
+
+ fixtures("forge_modules").each do |remote, opts|
+ if opts.instance_of?(String)
+ target = opts
+ ref = ""
+ elsif opts.instance_of?(Hash)
+ target = opts["target"]
+ ref = "--version #{opts['ref']}"
+ end
+ next if File::exists?(target)
+ unless system("puppet module install " + ref + \
+ " --ignore-dependencies" \
+ " --force" \
+ " --target-dir spec/fixtures/modules #{remote}")
+ fail "Failed to install module #{remote} to #{target}"
+ end
end
FileUtils::mkdir_p("spec/fixtures/manifests")
@@ -87,13 +159,23 @@ task :spec_clean do
FileUtils::rm_rf(target)
end
+ fixtures("forge_modules").each do |remote, opts|
+ if opts.instance_of?(String)
+ target = opts
+ elsif opts.instance_of?(Hash)
+ target = opts["target"]
+ end
+ FileUtils::rm_rf(target)
+ end
+
fixtures("symlinks").each do |source, target|
- FileUtils::rm(target)
+ FileUtils::rm_f(target)
end
- site = "spec/fixtures/manifests/site.pp"
- if File::exists?(site) and ! File.size?(site)
- FileUtils::rm("spec/fixtures/manifests/site.pp")
+
+ if File.zero?("spec/fixtures/manifests/site.pp")
+ FileUtils::rm_f("spec/fixtures/manifests/site.pp")
end
+
end
desc "Run spec tests in a clean fixtures directory"
@@ -103,6 +185,14 @@ task :spec do
Rake::Task[:spec_clean].invoke
end
+desc "List available beaker nodesets"
+task :beaker_nodes do
+ Dir['spec/acceptance/nodesets/*.yml'].sort!.select { |node|
+ node.slice!('.yml')
+ puts File.basename(node)
+ }
+end
+
desc "Build puppet module package"
task :build do
# This will be deprecated once puppet-module is a face.
@@ -120,9 +210,48 @@ task :clean do
FileUtils.rm_rf("pkg/")
end
-desc "Check puppet manifests with puppet-lint"
-task :lint do
- require 'puppet-lint/tasks/puppet-lint'
+require 'puppet-lint/tasks/puppet-lint'
+# Must clear as it will not override the existing puppet-lint rake task since we require to import for
+# the PuppetLint::RakeTask
+Rake::Task[:lint].clear
+# Relative is not able to be set within the context of PuppetLint::RakeTask
+PuppetLint.configuration.relative = true
+PuppetLint::RakeTask.new(:lint) do |config|
+ config.fail_on_warnings = true
+ config.disable_checks = [
+ '80chars',
+ 'class_inherits_from_params_class',
+ 'class_parameter_defaults',
+ 'documentation',
+ 'single_quote_string_with_variables']
+ config.ignore_paths = ["tests/**/*.pp", "vendor/**/*.pp","examples/**/*.pp" "spec/**/*.pp", "pkg/**/*.pp"]
+end
+
+require 'puppet-syntax/tasks/puppet-syntax'
+PuppetSyntax.exclude_paths ||= []
+PuppetSyntax.exclude_paths << "spec/fixtures/**/*"
+PuppetSyntax.exclude_paths << "pkg/**/*"
+PuppetSyntax.exclude_paths << "vendor/**/*"
+PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'yes'
+
+desc "Check syntax of Ruby files and call :syntax and :metadata"
+task :validate do
+ Dir['lib/**/*.rb'].each do |lib_file|
+ sh "ruby -c #{lib_file}"
+ end
+
+ Rake::Task[:syntax].invoke
+ Rake::Task[:metadata].invoke if File.exist?('metadata.json')
+end
+
+desc "Validate metadata.json file"
+task :metadata do
+ begin
+ require 'metadata_json_lint'
+ sh "metadata-json-lint metadata.json"
+ rescue LoadError => e
+ warn "Skipping metadata validation; the metadata-json-lint gem was not found"
+ end
end
desc "Display the list of available rake tasks"
diff --git a/lib/puppetlabs_spec_helper/version.rb b/lib/puppetlabs_spec_helper/version.rb
new file mode 100644
index 0000000..1c3cef7
--- /dev/null
+++ b/lib/puppetlabs_spec_helper/version.rb
@@ -0,0 +1,5 @@
+module PuppetlabsSpecHelper
+ module Version
+ STRING = '0.10.3'
+ end
+end
diff --git a/metadata.yml b/metadata.yml
index d356f56..dcefe60 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,94 +1,100 @@
---- !ruby/object:Gem::Specification
+--- !ruby/object:Gem::Specification
name: puppetlabs_spec_helper
-version: !ruby/object:Gem::Version
- hash: 13
- prerelease:
- segments:
- - 0
- - 4
- - 1
- version: 0.4.1
+version: !ruby/object:Gem::Version
+ version: 0.10.3
platform: ruby
-authors:
+authors:
- Puppet Labs
autorequire:
bindir: bin
cert_chain: []
-
-date: 2013-02-08 00:00:00 Z
-dependencies:
-- !ruby/object:Gem::Dependency
+date: 2015-05-11 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
name: rake
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+ type: :runtime
prerelease: false
- requirement: &id001 !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: rspec-puppet
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
type: :runtime
- version_requirements: *id001
-- !ruby/object:Gem::Dependency
- name: rspec
prerelease: false
- requirement: &id002 !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 43
- segments:
- - 2
- - 9
- - 0
- version: 2.9.0
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: puppet-lint
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
type: :runtime
- version_requirements: *id002
-- !ruby/object:Gem::Dependency
- name: mocha
prerelease: false
- requirement: &id003 !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 61
- segments:
- - 0
- - 10
- - 5
- version: 0.10.5
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: puppet-syntax
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
type: :runtime
- version_requirements: *id003
-- !ruby/object:Gem::Dependency
- name: rspec-puppet
prerelease: false
- requirement: &id004 !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 25
- segments:
- - 0
- - 1
- - 1
- version: 0.1.1
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: mocha
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
type: :runtime
- version_requirements: *id004
-description: Contains rake tasks and a standard spec_helper for running spec tests on puppet modules
-email:
-- puppet-dev at puppetlabs.com
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+description: Contains rake tasks and a standard spec_helper for running spec tests
+ on puppet modules
+email:
+- modules-dept at puppetlabs.com
executables: []
-
extensions: []
-
extra_rdoc_files: []
-
-files:
+files:
+- .gitignore
+- .noexec.yaml
+- CHANGELOG.md
+- Gemfile
+- LICENSE
+- README.markdown
+- Rakefile
- lib/puppetlabs_spec_helper/module_spec_helper.rb
- lib/puppetlabs_spec_helper/puppet_spec_helper.rb
- lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb
@@ -97,40 +103,41 @@ files:
- lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
- lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb
- lib/puppetlabs_spec_helper/rake_tasks.rb
-- LICENSE
-- CHANGELOG
+- lib/puppetlabs_spec_helper/version.rb
+- puppet_spec_helper.rb
+- puppetlabs_spec_helper.gemspec
+- puppetlabs_spec_helper.rb
+- spec/lib/puppet/type/spechelper.rb
+- spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb
+- spec/unit/spechelper_spec.rb
+- spec/watchr.rb
homepage: http://github.com/puppetlabs/puppetlabs_spec_helper
-licenses: []
-
+licenses:
+- Apache-2.0
+metadata: {}
post_install_message:
rdoc_options: []
-
-require_paths:
+require_paths:
- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
-required_rubygems_version: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
requirements: []
-
rubyforge_project:
-rubygems_version: 1.8.24
+rubygems_version: 2.4.5
signing_key:
-specification_version: 3
+specification_version: 4
summary: Standard tasks and configuration for module spec tests
-test_files: []
-
+test_files:
+- spec/lib/puppet/type/spechelper.rb
+- spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb
+- spec/unit/spechelper_spec.rb
+- spec/watchr.rb
+has_rdoc:
diff --git a/puppet_spec_helper.rb b/puppet_spec_helper.rb
new file mode 100644
index 0000000..d468569
--- /dev/null
+++ b/puppet_spec_helper.rb
@@ -0,0 +1,5 @@
+$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
+
+require 'puppetlabs_spec_helper/puppet_spec_helper'
+
+puts "Using 'PROJECT_ROOT/puppet_spec_helper' is deprecated, please install as a gem and require 'puppetlabs_spec_helper/puppet_spec_helper' instead"
diff --git a/puppetlabs_spec_helper.gemspec b/puppetlabs_spec_helper.gemspec
new file mode 100644
index 0000000..8942d15
--- /dev/null
+++ b/puppetlabs_spec_helper.gemspec
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
+require "puppetlabs_spec_helper/version"
+
+Gem::Specification.new do |s|
+ s.name = "puppetlabs_spec_helper"
+ s.version = PuppetlabsSpecHelper::Version::STRING
+ s.authors = ["Puppet Labs"]
+ s.email = ["modules-dept at puppetlabs.com"]
+ s.homepage = "http://github.com/puppetlabs/puppetlabs_spec_helper"
+ s.summary = "Standard tasks and configuration for module spec tests"
+ s.description = "Contains rake tasks and a standard spec_helper for running spec tests on puppet modules"
+ s.licenses = 'Apache-2.0'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+
+ # Runtime dependencies, but also probably dependencies of requiring projects
+ s.add_runtime_dependency 'rake'
+ s.add_runtime_dependency 'rspec-puppet'
+ s.add_runtime_dependency 'puppet-lint'
+ s.add_runtime_dependency 'puppet-syntax'
+ s.add_runtime_dependency 'mocha'
+end
diff --git a/puppetlabs_spec_helper.rb b/puppetlabs_spec_helper.rb
new file mode 100644
index 0000000..cf174ae
--- /dev/null
+++ b/puppetlabs_spec_helper.rb
@@ -0,0 +1,5 @@
+$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
+
+require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
+
+puts "Using 'PROJECT_ROOT/puppetlabs_spec_helper' is deprecated, please install as a gem and require 'puppetlabs_spec_helper/puppetlabs_spec_helper' instead"
diff --git a/spec/lib/puppet/type/spechelper.rb b/spec/lib/puppet/type/spechelper.rb
new file mode 100644
index 0000000..0122d7e
--- /dev/null
+++ b/spec/lib/puppet/type/spechelper.rb
@@ -0,0 +1,6 @@
+require 'puppet/type'
+
+Puppet::Type.newtype(:spechelper) do
+ @doc = "This is the spechelper type"
+end
+
diff --git a/spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb b/spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb
new file mode 100644
index 0000000..18f95be
--- /dev/null
+++ b/spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb
@@ -0,0 +1,92 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'puppetlabs_spec_helper/puppet_spec_helper'
+require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
+
+describe PuppetlabsSpec::PuppetInternals do
+ describe ".scope" do
+ it "should return a Puppet::Parser::Scope instance" do
+ subject.scope.should be_a_kind_of Puppet::Parser::Scope
+ end
+
+ it "should be suitable for function testing" do
+ scope = subject.scope
+ scope.function_split(["one;two", ";"]).should == [ 'one', 'two' ]
+ end
+
+ it "should accept a compiler" do
+ compiler = subject.compiler
+
+ scope = subject.scope(:compiler => compiler)
+
+ scope.compiler.should == compiler
+ end
+
+ it "should have a source set" do
+ scope = subject.scope
+
+ scope.source.should_not be_nil
+ scope.source.should_not be_false
+ end
+ end
+
+ describe ".resource" do
+ it "can have a defined type" do
+ subject.resource(:type => :node).type.should == :node
+ end
+
+ it "defaults to a type of hostclass" do
+ subject.resource.type.should == :hostclass
+ end
+
+ it "can have a defined name" do
+ subject.resource(:name => "testingrsrc").name.should == "testingrsrc"
+ end
+
+ it "defaults to a name of testing" do
+ subject.resource.name.should == "testing"
+ end
+ end
+
+ describe ".compiler" do
+ let(:node) { subject.node }
+
+ it "can have a defined node" do
+ subject.compiler(:node => node).node.should be node
+ end
+ end
+
+ describe ".node" do
+ it "can have a defined name" do
+ subject.node(:name => "mine").name.should == "mine"
+ end
+
+ it "can have a defined environment" do
+ subject.node(:environment => "mine").environment.name.should == :mine
+ end
+
+ it "defaults to a name of testinghost" do
+ subject.node.name.should == "testinghost"
+ end
+
+ it "accepts facts via options for rspec-puppet" do
+ fact_values = { 'fqdn' => "jeff.puppetlabs.com" }
+ node = subject.node(:options => { :parameters => fact_values })
+ node.parameters.should == fact_values
+ end
+ end
+
+ describe ".function_method" do
+ it "accepts an injected scope" do
+ Puppet::Parser::Functions.expects(:function).with("my_func").returns(true)
+ scope = mock()
+ scope.expects(:method).with(:function_my_func).returns(:fake_method)
+ subject.function_method("my_func", :scope => scope).should == :fake_method
+ end
+ it "returns nil if the function doesn't exist" do
+ Puppet::Parser::Functions.expects(:function).with("my_func").returns(false)
+ scope = mock()
+ subject.function_method("my_func", :scope => scope).should be_nil
+ end
+ end
+end
diff --git a/spec/unit/spechelper_spec.rb b/spec/unit/spechelper_spec.rb
new file mode 100755
index 0000000..040d82d
--- /dev/null
+++ b/spec/unit/spechelper_spec.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+require 'puppetlabs_spec_helper/puppet_spec_helper'
+
+# ensure we can access puppet settings outside of any example group
+Puppet[:confdir]
+
+# set modulepath from which to load custom type
+Puppet[:modulepath] = File.join(File.dirname(__FILE__), '..', '..')
+
+def should_be_able_to_load_types?
+ return true if Puppet::Test::TestHelper.respond_to?(:initialize)
+
+ case Puppet.version
+ when /^2\.7\.20/
+ false
+ when /^3\.0\./
+ false
+ else
+ true
+ end
+end
+
+# construct a top-level describe block whose declared_class is a custom type in this module
+describe Puppet::Type.type(:spechelper) do
+ it "should load the type from the modulepath" do
+ pending("this is only supported on newer versions of puppet", :unless => should_be_able_to_load_types?) do
+ described_class.should be
+ end
+ end
+
+ it "should have a doc string" do
+ pending("this is only supported on newer versions of puppet", :unless => should_be_able_to_load_types?) do
+ described_class.doc.should == "This is the spechelper type"
+ end
+ end
+end
+
+describe "Setup of settings" do
+ it "sets confdir and vardir to something not meaningful to force tests to make their choice explicit" do
+ Puppet[:confdir].should == "/dev/null"
+ Puppet[:vardir].should == "/dev/null"
+ end
+end
diff --git a/spec/watchr.rb b/spec/watchr.rb
new file mode 100644
index 0000000..9b46153
--- /dev/null
+++ b/spec/watchr.rb
@@ -0,0 +1,79 @@
+ENV['FOG_MOCK'] ||= 'true'
+ENV['AUTOTEST'] = 'true'
+ENV['WATCHR'] = '1'
+
+system 'clear'
+
+def growl(message)
+ growlnotify = `which growlnotify`.chomp
+ title = "Watchr Test Results"
+ image = case message
+ when /(\d+)\s+?(failure|error)/i
+ ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
+ else
+ '~/.watchr_images/unknown.png'
+ end
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
+ system %(#{growlnotify} #{options} &)
+end
+
+def run(cmd)
+ puts(cmd)
+ `#{cmd}`
+end
+
+def run_spec_test(file)
+ if File.exist? file
+ result = run "rspec --format p --color #{file}"
+ growl result.split("\n").last
+ puts result
+ else
+ puts "FIXME: No test #{file} [#{Time.now}]"
+ end
+end
+
+def filter_rspec(data)
+ data.split("\n").find_all do |l|
+ l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
+ end.join("\n")
+end
+
+def run_all_tests
+ system('clear')
+ files = Dir.glob("spec/**/*_spec.rb").join(" ")
+ result = run "rspec #{files}"
+ growl_results = filter_rspec result
+ growl growl_results
+ puts result
+ puts "GROWL: #{growl_results}"
+end
+
+# Ctrl-\
+Signal.trap 'QUIT' do
+ puts " --- Running all tests ---\n\n"
+ run_all_tests
+end
+
+ at interrupted = false
+
+# Ctrl-C
+Signal.trap 'INT' do
+ if @interrupted then
+ @wants_to_quit = true
+ abort("\n")
+ else
+ puts "Interrupt a second time to quit"
+ @interrupted = true
+ Kernel.sleep 1.5
+ # raise Interrupt, nil # let the run loop catch it
+ run_suite
+ end
+end
+
+watch( 'spec/.*_spec\.rb' ) do |md|
+ run_all_tests
+end
+
+watch( 'lib/.*\.rb' ) do |md|
+ run_all_tests
+end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-puppetlabs-spec-helper.git
More information about the Pkg-ruby-extras-commits
mailing list