pax_global_header00006660000000000000000000000064132403553610014514gustar00rootroot0000000000000052 comment=4d7741f91b7c51ec759432ea2cdaf4ac6260d060 puppetlabs_spec_helper-2.6.2/000077500000000000000000000000001324035536100162535ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/.gitignore000066400000000000000000000001271324035536100202430ustar00rootroot00000000000000/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ puppetlabs_spec_helper-2.6.2/.noexec.yaml000066400000000000000000000000371324035536100204760ustar00rootroot00000000000000--- exclude: - rake - rspec puppetlabs_spec_helper-2.6.2/.rspec000066400000000000000000000000371324035536100173700ustar00rootroot00000000000000--format documentation --color puppetlabs_spec_helper-2.6.2/.rubocop.yml000066400000000000000000000160111324035536100205240ustar00rootroot00000000000000require: rubocop-rspec AllCops: TargetRubyVersion: 1.9 Include: - ./**/*.rb Lint/ConditionPosition: Enabled: True Lint/ElseLayout: Enabled: True Lint/UnreachableCode: Enabled: True Lint/UselessComparison: Enabled: True Lint/EnsureReturn: Enabled: True Lint/HandleExceptions: Enabled: True Lint/LiteralInCondition: Enabled: True Lint/ShadowingOuterLocalVariable: Enabled: True Lint/LiteralInInterpolation: Enabled: True Style/HashSyntax: Enabled: True Style/RedundantReturn: Enabled: True Lint/AmbiguousOperator: Enabled: True Lint/AssignmentInCondition: Enabled: True Style/SpaceBeforeComment: Enabled: True Style/AndOr: Enabled: True Style/RedundantSelf: Enabled: True # Method length is not necessarily an indicator of code quality Metrics/MethodLength: Enabled: False # Module length is not necessarily an indicator of code quality Metrics/ModuleLength: Enabled: False Style/WhileUntilModifier: Enabled: True Lint/AmbiguousRegexpLiteral: Enabled: True Lint/Eval: Enabled: True Lint/BlockAlignment: Enabled: True Lint/DefEndAlignment: Enabled: True Lint/EndAlignment: Enabled: True Lint/DeprecatedClassMethods: Enabled: True Lint/Loop: Enabled: True Lint/ParenthesesAsGroupedExpression: Enabled: True Lint/RescueException: Enabled: True Lint/StringConversionInInterpolation: Enabled: True Lint/UnusedBlockArgument: Enabled: True Lint/UnusedMethodArgument: Enabled: True Lint/UselessAccessModifier: Enabled: True Lint/UselessAssignment: Enabled: True Lint/Void: Enabled: True Style/AccessModifierIndentation: Enabled: True Style/AccessorMethodName: Enabled: True Style/Alias: Enabled: True Style/AlignArray: Enabled: True Style/AlignHash: Enabled: True Style/AlignParameters: Enabled: True Metrics/BlockNesting: Enabled: True Style/AsciiComments: Enabled: True Style/Attr: Enabled: True Style/BracesAroundHashParameters: Enabled: True Style/CaseEquality: Enabled: True Style/CaseIndentation: Enabled: True Style/CharacterLiteral: Enabled: True Style/ClassAndModuleCamelCase: Enabled: True Style/ClassAndModuleChildren: Enabled: False Style/ClassCheck: Enabled: True # Class length is not necessarily an indicator of code quality Metrics/ClassLength: Enabled: False Style/ClassMethods: Enabled: True Style/ClassVars: Enabled: True Style/WhenThen: Enabled: True Style/WordArray: Enabled: True Style/UnneededPercentQ: Enabled: True Style/Tab: Enabled: True Style/SpaceBeforeSemicolon: Enabled: True Style/TrailingBlankLines: Enabled: True Style/SpaceInsideBlockBraces: Enabled: True Style/SpaceInsideBrackets: Enabled: True Style/SpaceInsideHashLiteralBraces: Enabled: True Style/SpaceInsideParens: Enabled: True Style/LeadingCommentSpace: Enabled: True Style/SpaceBeforeFirstArg: Enabled: True Style/SpaceAfterColon: Enabled: True Style/SpaceAfterComma: Enabled: True Style/SpaceAfterMethodName: Enabled: True Style/SpaceAfterNot: Enabled: True Style/SpaceAfterSemicolon: Enabled: True Style/SpaceAroundEqualsInParameterDefault: Enabled: True Style/SpaceAroundOperators: Enabled: True Style/SpaceBeforeBlockBraces: Enabled: True Style/SpaceBeforeComma: Enabled: True Style/CollectionMethods: Enabled: True Style/CommentIndentation: Enabled: True Style/ColonMethodCall: Enabled: True Style/CommentAnnotation: Enabled: True # 'Complexity' is very relative Metrics/CyclomaticComplexity: Enabled: False Style/ConstantName: Enabled: True Style/Documentation: Enabled: False Style/DefWithParentheses: Enabled: True Style/PreferredHashMethods: Enabled: True Style/DotPosition: EnforcedStyle: trailing Style/DoubleNegation: Enabled: True Style/EachWithObject: Enabled: True Style/EmptyLineBetweenDefs: Enabled: True Style/IndentArray: Enabled: True Style/IndentHash: Enabled: True Style/IndentationConsistency: Enabled: True Style/IndentationWidth: Enabled: True Style/EmptyLines: Enabled: True Style/EmptyLinesAroundAccessModifier: Enabled: True Style/EmptyLiteral: Enabled: True # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Enabled: False Style/MethodCallParentheses: Enabled: True Style/MethodDefParentheses: Enabled: True Style/LineEndConcatenation: Enabled: True Style/TrailingWhitespace: Enabled: True Style/StringLiterals: Enabled: True Style/TrailingCommaInArguments: Enabled: True Style/TrailingCommaInLiteral: Enabled: True Style/GlobalVars: Enabled: True Style/GuardClause: Enabled: True Style/IfUnlessModifier: Enabled: True Style/MultilineIfThen: Enabled: True Style/NegatedIf: Enabled: True Style/NegatedWhile: Enabled: True Style/Next: Enabled: True Style/SingleLineBlockParams: Enabled: True Style/SingleLineMethods: Enabled: True Style/SpecialGlobalVars: Enabled: True Style/TrivialAccessors: Enabled: True Style/UnlessElse: Enabled: True Style/VariableInterpolation: Enabled: True Style/VariableName: Enabled: True Style/WhileUntilDo: Enabled: True Style/EvenOdd: Enabled: True Style/FileName: Enabled: True Style/For: Enabled: True Style/Lambda: Enabled: True Style/MethodName: Enabled: True Style/MultilineTernaryOperator: Enabled: True Style/NestedTernaryOperator: Enabled: True Style/NilComparison: Enabled: True Style/FormatString: Enabled: True Style/MultilineBlockChain: Enabled: True Style/Semicolon: Enabled: True Style/SignalException: Enabled: True Style/NonNilCheck: Enabled: True Style/Not: Enabled: True Style/NumericLiterals: Enabled: True Style/OneLineConditional: Enabled: True Style/OpMethod: Enabled: True Style/ParenthesesAroundCondition: Enabled: True Style/PercentLiteralDelimiters: Enabled: True Style/PerlBackrefs: Enabled: True Style/PredicateName: Enabled: True Style/RedundantException: Enabled: True Style/SelfAssignment: Enabled: True Style/Proc: Enabled: True Style/RaiseArgs: Enabled: True Style/RedundantBegin: Enabled: True Style/RescueModifier: Enabled: True # based on https://github.com/voxpupuli/modulesync_config/issues/168 Style/RegexpLiteral: EnforcedStyle: percent_r Enabled: True Lint/UnderscorePrefixedVariableName: Enabled: True Metrics/ParameterLists: Enabled: False Lint/RequireParentheses: Enabled: True Style/SpaceBeforeFirstArg: Enabled: True Style/ModuleFunction: Enabled: True Lint/Debugger: Enabled: True Style/IfWithSemicolon: Enabled: True Style/Encoding: Enabled: True Style/BlockDelimiters: Enabled: True Style/MultilineBlockLayout: Enabled: True # 'Complexity' is very relative Metrics/AbcSize: Enabled: False # 'Complexity' is very relative Metrics/PerceivedComplexity: Enabled: False Lint/UselessAssignment: Enabled: True Style/ClosingParenthesisIndentation: Enabled: False # RSpec # We don't use rspec in this way RSpec/DescribeClass: Enabled: False # Example length is not necessarily an indicator of code quality RSpec/ExampleLength: Enabled: False RSpec/NamedSubject: Enabled: False puppetlabs_spec_helper-2.6.2/.travis.yml000066400000000000000000000007431324035536100203700ustar00rootroot00000000000000sudo: false language: ruby cache: bundler before_install: # https://github.com/bundler/bundler/issues/3558 gem update bundler script: bundle exec rake spec matrix: fast_finish: true include: - rvm: 2.3.1 env: PUPPET_GEM_VERSION='~> 4.0' - rvm: 2.1 env: PUPPET_GEM_VERSION='~> 4.0' - rvm: 2.1 env: PUPPET_GEM_VERSION='~> 3.0' - rvm: 2.0 env: PUPPET_GEM_VERSION='~> 3.0' - rvm: 1.9.3 env: PUPPET_GEM_VERSION='~> 3.0' notifications: email: false puppetlabs_spec_helper-2.6.2/CHANGELOG.md000066400000000000000000000411531324035536100200700ustar00rootroot00000000000000# Change log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [2.6.2] ### Summary A bugfix release to remove dependency on GettextSetup.initialize() in the Rake tasks. ## [2.6.1] ### Summary Includes changes for 2.6.0 plus tests and bugfix of said feature. ## 2.6.0 - Yanked ### Summary Adds a `defaults` section to `.fixtures.yml` to specify properties such as `flags` that apply to all fixtures in a category. One example use case is to specify an alternate forge URI for the `forge_modules` fixtures. ### Added - Add `defaults` section to fixtures. ## [2.5.1] ### Summary Adds a fix to the parallel_spec rake task. ### Fixed - In parallel_spec, warn when there are no files to test against rather than fail. ## [2.5.0] ### Summary Adds a feature to pass test file targets from 'rake spec' to 'rspec', also fixes a parsing issue with test\_tiers. ### Added - Allows passing test file targets through to 'rspec' from 'rake spec'. ### Fixed - Trim whitespace from test\_tiers before parsing. ## [2.4.0] ### Summary Fix mercurial stuff, allow fixtures other than spec/fixtures/modules/, and allow running specific tags for beaker tests. ### Added - Ability to check out branches in mercurial - Ability to target alternative locations to clone fixtures - `TEST_TIERS` environment variable for beaker rake task ### Fixed - mercurial cleanup command - handle parallel spec load failure better ## [2.3.2] ### Summary Cleanups and fixes around fixture handling. ### Fixed - Do not error when no fixtures file is found or specified. - Clean up fixtures, even if tests fail. Especially on Windows this is important to not keep lingering symlinks around. - Fix creating of directory junctions (symlinks) on Windows for fixtures. ## [2.3.1] ### Summary Adds a `spec_list_json` rake task ### Added - `spec_list_json` rake task to output a module's spec tests as a JSON document ## [2.3.0] ### Added - `CI_SPEC_OPTIONS` environment variable for `parallel_spec` rake task ### Fixed - Remove puppet ~> 3.0 pin from gemspec ## [2.2.0] ### Summary i18n rake task, and unbreak windows again. ### Added - New rake task for i18n stuff. ### Fixed - Fixture path calculation for windows - Log to stderr instead of stdout as per rspec's spec ## [2.1.5] ### Summary: Fix symlinks fixtures code. ## [2.1.4] ### Summary: Better Windows support. ### Fixed: - Create directory junctions instead of symlinks on windows (#192) - Replace check:symlinks with platform independent alternative (#193) ## [2.1.3] ### Summary: This release fixes puppet module install into paths with spaces, and fix conflicting build names for CI jobs. ### Fixed: - Properly exscape paths for puppet module install - Add "r" to the beginning of `rake compute_dev_version` ## [2.1.2] ### Summary: The `release_tasks` now falls back to `spec` if the `parallel_spec` test fails due to the `parallel_tests` gem being absent. ### Fixed: - Make `release_tasks` fall back to `spec` when missing the `parallel_tests` gem ## [2.1.1] ### Summary: Bugfix for an unstated dependency on parallel\_spec that was added in 2.0.0 ### Fixed: - Add dependency for parallel\_spec, since psh requires it anyway. ## [2.1.0] ### Summary: Minor version bump for new CI_SPEC_OPTIONS variable and bug fix. ### Added: - use CI_SPEC_OPTIONS to pass options to rspec ### Fixed: - an issue where gettext:setup tasks were being loaded in the wrong order within a module and causing the POT file to be created in the Puppet gem, not the module. ## [2.0.2] ### Summary: Fixes an issue where the gettext rake tasks look in the spec\_helper and not the current module for the `locales/` directory. ## [2.0.1] ### Summary: Fixes an issue where older puppets don't bring in the gettext gem requirement causing the psh rake tasks to fail. ### Fixed: - Don't define gettext rake tasks if gettext library is not present ## [2.0.0] ### Summary: This release makes the module working dir configurable, adds features for future puppet features, and updates the spec rake task for TravisCI ### Changed: - The `release_tasks` rake task now calls `parallel_spec` instead of `spec` ### Added: - Make `module_working_dir` configurable - Check `type_aliases` directory for spec tests - Locales support for i18n ### Fixed: - Ensure /-only used on windows ## [1.2.2] ### Summary: Dominic Cleal reported and fixed an issue with the STRICT_VARIABLES setting on puppet versions before 3.5. ## [1.2.1] ### Summary: The previous release was taken down, as some optional gem dependencies slipped through into the gemspec, breaking builds using ruby 2.2 and earlier. This release updates the gem build process, so this should not happen again. ## [1.2.0] - 2016-08-23 ### Summary: Add a bunch of new features, and fix a bunch of annoying bugs: parallel test execution, default to strict variable checking on Puppet 4, code coverage, and rubocop tasks. Thanks to all community contributors: Alexander Fisher, Alex Harvey, Chris Tessmer, David Moreno García, Dmitry Ilyin, Dominic Cleal, Federico Voges, Garrett Honeycutt, Leo Arnold, Matthew Haughton, Mickaël Canévet, and Rob Nelson. ### Added: New tasks: * Add code coverage for Ruby >= 1.9 using SimpleCov. * Add a rubocop rake task. * Use beaker:ssh to log into your running beaker machines. Spec parallelization * Add `parallel_spec` task to run specs in parallel. * Use CI_NODE_TOTAL and CI_NODE_INDEX to split tests across nodes. Fixtures improvements: * Automatically symlink the module directory, if no symlink fixtures are specified. * Add the `subdir` key to repository fixtures to only use a part of that repository. * Set `FIXTURES_YML` environment variable to load fixtures from somewhere else than `.fixtures.yml`. ## Changed: * Updated default excludes and rspec patterns. * Updated default disabled lint checks to work with puppet-lint 2.0.0. * Testing on Puppet 4 will now default to strict variable checking. Set STRICT_VARIABLES=no to disable. * `PuppetInternals.scope` is now deprecated. Use the new `scope` property from rspec-puppet. * beaker_nodes is now called beaker:sets. ### Fixed: * Ignore symlinks inside .git when running check:symlinks rake task. * Allow multiple invocations of spec_prep to run in parallel. * Address a race condition when cloning multiple git fixtures. * Restrict gem dependencies to work with ruby 1.9. * Update verify_contents() to work with duplicates in the arguments. ## [1.1.1] - 2016-03-02 ### Fixed: Readded and properly deprecated the `metadata` rake task. Use the `metadata_lint` task from metadata-json-lint directly instead. ## [1.1.0] - 2016-02-25 ### Summary: This release adds the ability to clone fixtures from git in parallel, speeding up the spec\_prep rake task. ### Added: - Parallel fixtures cloning - Various rake check tasks for module release preparation ### Fixed: - Added travis ci - Added contributing doc - Don't validate metadata if metadata-json-lint gem is not present ## [1.0.1] - 2015-11-06 ### Summary: This bugfix release fixes the Error vs. Errno bug in 1.0.0 ### Fixed: - Raise `Errno::ENOENT` instead of `Error::ENOENT` ## [1.0.0] - 2015-11-04 ### Summary: The first 1.0 release, though the gem has been considered stable for a while. ### Added: - `flags` value for fixtures to allow passing CLI flags when installing modules - `spec_standalone` rake task also runs `spec/types` specs - Can now use `.fixtures.yaml` instead of `.fixtures.yml` ### Fixed: - Remove double-initialization that was conflicting with rspec-puppet - Better error handling on malformed fixtures yaml - Bug in rake task's ignore\_paths ## [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=` 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/v2.6.2...master [2.6.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.6.1...v2.6.2 [2.6.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.5.1...v2.6.1 [2.5.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.5.0...v2.5.1 [2.5.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.4.0...v2.5.0 [2.4.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.3.2...v2.4.0 [2.3.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.3.1...v2.3.2 [2.3.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.3.0...v2.3.1 [2.3.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.2.0...v2.3.0 [2.2.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.1.5...v2.2.0 [2.1.5]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.1.4...v2.1.5 [2.1.4]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.1.3...v2.1.4 [2.1.3]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.1.2...v2.1.3 [2.1.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.1.1...v2.1.2 [2.1.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.1.0...v2.1.1 [2.1.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.0.1...v2.1.0 [2.0.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.0.0...v2.0.1 [2.0.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v1.2.2...v2.0.0 [1.2.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v1.2.1...v1.2.2 [1.2.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/1.2.0...v1.2.1 [1.2.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/1.1.1...1.2.0 [1.1.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/1.1.0...1.1.1 [1.1.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/1.0.1...1.1.0 [1.0.1]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/1.0.0...1.0.1 [1.0.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.10.3...1.0.0 [0.10.3]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/0.10.2...0.10.3 [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 puppetlabs_spec_helper-2.6.2/CONTRIBUTING.md000066400000000000000000000011621324035536100205040ustar00rootroot00000000000000# DEVELOPMENT NOTES ## Building Gemspec To keep the gem accessible to people running older rubies, the gemspec may only contain dependencies on gems that are available to all supported rubies. Features that need gems compatible only to some versions of ruby need to be coded in a way that is optional, and specify their gem dependencies in the Gemfile, conditional on the ruby version. Add a note to the README about those. ## Releasing To release the gem run the following things. ### 1. Update the version update the version file: `lib/puppetlabs_spec_helper/version.rb` ### 2. Release the gem rake release[remote] puppetlabs_spec_helper-2.6.2/Gemfile000066400000000000000000000013761324035536100175550ustar00rootroot00000000000000source 'https://rubygems.org' # Specify the global dependencies in puppetlabs_spec_helper.gemspec # Note that only ruby 1.9 compatible dependencies may go there, everything else needs to be documented and pulled in manually, and optionally by everyone who wants to use the extended features. gemspec group :development do gem "puppet", ENV['PUPPET_GEM_VERSION'] || ENV['PUPPET_VERSION'] || '~> 4.0' if RUBY_VERSION =~ /^1\./ gem 'rubocop', '0.41.2' else gem 'rubocop' gem 'rubocop-rspec', '~> 1.6' if RUBY_VERSION >= '2.3.0' end end # json_pure 2.0.2 added a requirement on ruby >= 2. We pin to json_pure 2.0.1 # if using ruby 1.x gem 'json_pure', '<=2.0.1', :require => false if RUBY_VERSION =~ /^1\./ gem 'rack', '~> 1' # vim:filetype=ruby puppetlabs_spec_helper-2.6.2/LICENSE000066400000000000000000000011461324035536100172620ustar00rootroot00000000000000Copyright (C) 2012 Puppet Labs Inc Puppet Labs can be contacted at: info@puppetlabs.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.puppetlabs_spec_helper-2.6.2/README.md000066400000000000000000000405111324035536100175330ustar00rootroot00000000000000Puppet 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. The recommended way to do this is using [bundler](http://bundler.io/#getting-started). Example Gemfile: source 'https://rubygems.org' gem 'puppetlabs_spec_helper' 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 ### Parallel Fixture Downloads Fixture downloads will now execute in parallel to speed up the testing process. Which can represent >= 600% speed increase (depending on number of threads). You can control the amount of threads by setting the `MAX_FIXTURE_THREAD_COUNT` environment variable to a positive integer, the default is currently 10. We don't suggest going higher than 25 as the gains are marginal due to some repos taking a long time to download. Please be aware that your internal VCS system may not be able to handle a high load in which case the server would fail to clone the repository. Because of this issue, this setting is tunable via `MAX_FIXTURE_THREAD_COUNT`. Additionally, you can also speed up cloning when using the ssh protocol by multiplexing ssh sessions. Add something similar to your ssh config. Note: you may need to change the host if your using an internal git server. ```shell Host github.com ControlMaster auto ControlPath ~/.ssh/ssh-%r@%h:%p ControlPersist yes ``` Note: parallel downloads is only available for repositories and not forge modules. ### Parallel tests It is also possible to use the `parallel_tests` Gem via the `:parallel_spec` Rake task to run rspec commands in parallel on groups of spec files. Use of parallelization at this level can result in large performance benefits when the Rspec examples tend to cause a number of large, CPU-intensive catalog compilations to occur. An example of where this might be the case is in a complex module with a lot of tests or a control repo with many hosts. Be aware however that in other circumstances this parallelization can result in the tests actually taking longer to run. The best thing to do is time `rspec spec` and `rspec parallel_spec` and use the parallelization only when there is a clear benefit. To enable this feature, add the `parallel_tests` Gem to your project's Gemfile: gem 'parallel_tests' And then to run spec tests in parallel: $ rake parallel_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. Running on non-current ruby versions ------------------------------------ Since gem and bundler, ruby's package management tools, do not take the target ruby version into account when downloading packages, the puppetlabs_spec_helper gem can only depend on gems that are available for all supported ruby versions. If you can/want to use features from other packages, install those additional packages manually, or have a look at the Gemfile, which provides code to specify those dependencies in a more "friendly" way. This currently affects the following gems: * puppet * rubocop * rubocop-rspec * json_pure * rack 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 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. * ``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. You can specify a alternate location for that file in the `FIXTURES_YML` environment variable. You can use the `MODULE_WORKING_DIR` environment variable to specify a diffent location when installing module fixtures via the forge. By default the working directory is `/spec/fixtures/work-dir`. 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) * subdir - directory to be removed from the cloned repo. Its contents will be moved to the root directory (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` * flags - additional flags passed to the module installer (both puppet and scm) ```yaml flags: --verbose ``` **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: ```yaml fixtures: symlinks: my_module: "#{source_dir}" ``` This is the same as specifying no symlinks fixtures at all. Add `firewall` and `stdlib` as required module fixtures: ```yaml fixtures: repositories: firewall: "git://github.com/puppetlabs/puppetlabs-firewall" stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib" ``` Put a supplementary repository at a different location ```yaml fixtures: repositories: firewall: "git://github.com/puppetlabs/puppetlabs-firewall" stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib" control_repo: repo: "https://github.com/puppetlabs/control-repo" target: "spec/fixtures/control_repos" ``` Specify that the git tag `2.4.2` of `stdlib' should be checked out: ```yaml fixtures: repositories: firewall: "git://github.com/puppetlabs/puppetlabs-firewall" stdlib: repo: "git://github.com/puppetlabs/puppetlabs-stdlib" ref: "2.6.0" ``` Move manifests and siblings to root directory when they are inside a `code` directory: ```yaml fixtures: repositories: stdlib: repo: "git://github.com/puppetlabs/puppetlabs-extradirectory" subdir: "code" ``` Install modules from Puppet Forge: ```yaml fixtures: forge_modules: firewall: "puppetlabs/firewall" stdlib: repo: "puppetlabs/stdlib" ref: "2.6.0" ``` Pass additional flags to module installation: ```yaml fixtures: forge_modules: stdlib: repo: "puppetlabs/stdlib" ref: "2.6.0" flags: "--module_repository https://my_repo.com" repositories: firewall: repo: "git://github.com/puppetlabs/puppetlabs-firewall" ref: "2.6.0" flags: "--verbose" ``` Testing Parser Functions ======================== This whole section is superseded by improved support of accessing the scope in rspec-puppet. Modify rspec behavior ================================ #### Running Rspec with additional settings You can add command line options to rspec using the `CI_SPEC_OPTIONS` environment variable. Any text in the `CI_SPEC_OPTIONS` environment variable is added as an rspec option. For example: If you wanted to output JUnit test reports for a Jenkins CI server you could use; Bash ``` bash export CI_SPEC_OPTIONS = "-r yarjuf -f JUnit -o result.xml" ``` PowerShell ``` bash $ENV:CI_SPEC_OPTIONS = '-r yarjuf -f JUnit -o result.xml' ``` And then run ``` bundle exec rake spec ``` This would cause rspec to load the `yarjuf` gem and output the results in JUnit format to the file `result.xml` #### Running specs in parallel When executing tests in a matrix CI environment, tests can be split up to run a share of specs per CI node in parallel. Set the ``CI_NODE_TOTAL`` environment variable to the total number of nodes, and the ``CI_NODE_INDEX`` to a number between 1 and the ``CI_NODE_TOTAL``. If using Travis CI, add new lines to the "env" section of .travis.yml per node, remembering to duplicate any existing environment variables: env: - FUTURE_PARSER=yes CI_NODE_TOTAL=2 CI_NODE_INDEX=1 - FUTURE_PARSER=yes CI_NODE_TOTAL=2 CI_NODE_INDEX=2 #### Running tests tagged with test tiers To run tests tagged with risk levels set the ``TEST_TIERS`` environment variable to a comma-separated list of the appropriate tiers. For example: to run tests marked ``tier_high => true`` and ``tier_medium => true`` in the same test run set the environment variable``TEST_TIERS=high,medium`` Note, if the ``TEST_TIERS`` environment variable is set to empty string or nil, all tiers will be executed. Generating code coverage reports ================================ This section describes how to add code coverage reports for Ruby files (types, providers, ...). See the documentation of [RSpec-Puppet](https://github.com/rodjek/rspec-puppet) for Puppet manifest coverage reports. Starting with Ruby 1.9, the *de facto* standard for Ruby code coverage is [SimpleCov](https://github.com/colszowka/simplecov). You can add it to your module like this: ```Ruby # First line of spec/spec_helper.rb require 'simplecov' SimpleCov.start do add_filter '/spec/' # Exclude bundled Gems in `/.vendor/` add_filter '/.vendor/' end require 'puppetlabs_spec_helper/module_spec_helper' # Further content ``` The reports will then be generated every time you invoke RSpec, e.g. via `rake spec`, and are written to `/coverage/`, which you should add to `.gitignore`. Remember to add `gem 'simplecov', require: false` to your `Gemfile`. Using Code Climate ------------------ You can also use [Code Climate](https://codeclimate.com/) together with SimpleCov: ```Ruby # First line of spec/spec_helper.rb require 'codeclimate-test-reporter' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, CodeClimate::TestReporter::Formatter ] SimpleCov.start do add_filter '/spec/' # Exclude bundled Gems in `/.vendor/` add_filter '/.vendor/' end require 'puppetlabs_spec_helper/module_spec_helper' # Further content ``` Remember to add `gem 'codeclimate-test-reporter', require: false` to your `Gemfile`. Using Coveralls --------------- You can also use [Coveralls](https://coveralls.io/) together with SimpleCov: ```Ruby # First line of spec/spec_helper.rb require 'simplecov' require 'coveralls' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter ] SimpleCov.start do add_filter '/spec/' # Exclude bundled Gems in `/.vendor/` add_filter '/.vendor/' end require 'puppetlabs_spec_helper/module_spec_helper' # Further content ``` Remember to add `gem 'coveralls', require: false` to your `Gemfile`. Some Notes for Windows Users ============================ A windows users may need to do one of two things to execute `rake spec`. Although things may appear to work, the init.pp may not transfer to the fixtures folder as needed or may transfer as an empty file. This is related to a registry security setting requiring elevated privileges to create symbolic links. Currently, there are two known approaches to get around this problem. - run your windows shell (cmd) as an Administrator or - modify the registry entry settings to allow symbolic links to be created. The following links may give you some insight into why... [Server Fault Post](http://serverfault.com/questions/582944/puppet-file-link-doesnt-create-target-under-windows) [Stack Overflow Post](http://stackoverflow.com/questions/229643/how-do-i-overcome-the-the-symbolic-link-cannot-be-followed-because-its-type-is) [Microsoft TechNet](https://technet.microsoft.com/en-us/library/cc754077.aspx) EOF puppetlabs_spec_helper-2.6.2/Rakefile000066400000000000000000000005101324035536100177140ustar00rootroot00000000000000# encoding: utf-8 require "bundler/gem_tasks" require "rspec/core/rake_task" task :default => :spec RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList['spec/**/*_spec.rb'].exclude('spec/fixtures/**/*_spec.rb') end require 'rubocop/rake_task' RuboCop::RakeTask.new require 'yard' YARD::Rake::YardocTask.new puppetlabs_spec_helper-2.6.2/lib/000077500000000000000000000000001324035536100170215ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/000077500000000000000000000000001324035536100235515ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/module_spec_helper.rb000066400000000000000000000030161324035536100277340ustar00rootroot00000000000000require 'rspec-puppet' require 'puppetlabs_spec_helper/puppet_spec_helper' require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals' def param_value(subject, type, title, param) subject.resource(type, title).send(:parameters)[param.to_sym] end def verify_contents(subject, title, expected_lines) content = subject.resource('file', title).send(:parameters)[:content] expect(content.split("\n") & expected_lines).to match_array expected_lines.uniq end 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') 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' 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.version.to_f >= 4.0 && ENV['STRICT_VARIABLES'] != 'no') Puppet.settings[:ordering] = ENV['ORDERING'] if ENV['ORDERING'] end end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/puppet_spec_helper.rb000066400000000000000000000134271324035536100277730ustar00rootroot00000000000000require 'puppetlabs_spec_helper/puppetlabs_spec_helper' # Don't want puppet getting the command line arguments for rake or autotest ARGV.clear # This is needed because we're using mocha with rspec instead of Test::Unit or MiniTest ENV['MOCHA_OPTIONS']='skip_integration' require 'puppet' require 'rspec/expectations' require 'mocha/api' require 'pathname' require 'tmpdir' require 'puppetlabs_spec_helper/puppetlabs_spec/files' ###################################################################################### # WARNING # ###################################################################################### # # You should probably be frightened by this file. :) # # The goal of this file is to try to maximize spec-testing compatibility between # multiple versions of various external projects (which depend on puppet core) and # multiple versions of puppet core itself. This is accomplished via a series # of hacks and magical incantations that I am not particularly proud of. However, # after discussion it was decided that the goal of achieving compatibility was # a very worthy one, and that isolating the hacks to one place in a non-production # project was as good a solution as we could hope for. # # You may want to hold your nose before you proceed. :) # # Here we attempt to load the new TestHelper API, and print a warning if we are falling back # to compatibility mode for older versions of puppet. begin require 'puppet/test/test_helper' rescue LoadError => err 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.# module Puppet class 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) $stderr.puts("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 $puppet_application_name = nil # 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 end # JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534) if not Puppet.constants.include? "Test" then module Puppet::Test 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| # Some modules depend on having mocha set up for them config.mock_with :mocha # 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) end # Here we do some general setup that is relevant to all initialization modes, regardless # of the availability of the TestHelper API. config.before :each do # Here we redirect logging away from console, because otherwise the test output will be # obscured by all of the log output. # # TODO: in a more sane world, we'd move this logging redirection into our TestHelper # class, so that it was not coupled with a specific testing framework (rspec in this # case). Further, it would be nicer and more portable to encapsulate the log messages # into an object somewhere, rather than slapping them on an instance variable of the # actual test class--which is what we are effectively doing here. # # However, because there are over 1300 tests that are written to expect # this instance variable to be available--we can't easily solve this problem right now. @logs = [] Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) @log_level = Puppet::Util::Log.level end config.after :each do # clean up after the logging changes that we made before each test. # TODO: this should be abstracted in the future--see comments above the '@logs' block in the # "before" code above. @logs.clear Puppet::Util::Log.close_all Puppet::Util::Log.level = @log_level end end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/puppetlabs_spec/000077500000000000000000000000001324035536100267425ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb000077500000000000000000000024001324035536100303700ustar00rootroot00000000000000require 'fileutils' require 'tempfile' require 'pathname' # A support module for testing files. module PuppetlabsSpec::Files # This code exists only to support tests that run as root, pretty much. # Once they have finally been eliminated this can all go... --daniel 2011-04-08 def self.in_tmp(path) tempdir = Dir.tmpdir Pathname.new(path).ascend do |dir| return true if File.identical?(tempdir, dir) end false end def self.cleanup $global_tempfiles ||= [] while path = $global_tempfiles.pop do fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path) begin FileUtils.rm_r path, :secure => true rescue Errno::ENOENT # nothing to do end end end def make_absolute(path) path = File.expand_path(path) path[0] = 'c' if Puppet.features.microsoft_windows? path end def tmpfilename(name) # Generate a temporary file, just for the name... source = Tempfile.new(name) path = source.path source.close! # ...record it for cleanup, $global_tempfiles ||= [] $global_tempfiles << File.expand_path(path) # ...and bam. path end def tmpdir(name) path = tmpfilename(name) FileUtils.mkdir_p(path) path end end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb000077500000000000000000000032411324035536100311430ustar00rootroot00000000000000# This module provides some helper methods to assist with fixtures. It's # methods are designed to help when you have a conforming fixture layout so we # get project consistency. module PuppetlabsSpec::Fixtures # Returns the joined path of the global FIXTURE_DIR plus any path given to it def fixtures(*rest) File.join(PuppetlabsSpec::FIXTURE_DIR, *rest) end # Returns the path to your relative fixture dir. So if your spec test is # /spec/unit/facter/foo_spec.rb then your relative dir will be # /spec/fixture/unit/facter/foo def my_fixture_dir callers = caller while line = callers.shift do next unless found = line.match(%r{/spec/(.*)_spec\.rb:}) return fixtures(found[1]) end fail "sorry, I couldn't work out your path from the caller stack!" end # Given a name, returns the full path of a file from your relative fixture # dir as returned by my_fixture_dir. def my_fixture(name) file = File.join(my_fixture_dir, name) unless File.readable? file then fail "fixture '#{name}' for #{my_fixture_dir} is not readable" end return file end # Return the contents of the file using read when given a name. Uses # my_fixture to work out the relative path. def my_fixture_read(name) File.read(my_fixture(name)) end # Provides a block mechanism for iterating across the files in your fixture # area. def my_fixtures(glob = '*', flags = 0) files = Dir.glob(File.join(my_fixture_dir, glob), flags) unless files.length > 0 then fail "fixture '#{glob}' for #{my_fixture_dir} had no files!" end block_given? and files.each do |file| yield file end files end end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb000066400000000000000000000041521324035536100310770ustar00rootroot00000000000000require 'stringio' require 'rspec/expectations' ######################################################################## # Backward compatibility for Jenkins outdated environment. module RSpec module Matchers module BlockAliases 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 ######################################################################## # Custom matchers... RSpec::Matchers.define :have_matching_element do |expected| match do |actual| actual.any? { |item| item =~ expected } end end RSpec::Matchers.define :exit_with do |expected| actual = nil match do |block| begin block.call rescue SystemExit => e actual = e.status end actual and actual == expected end failure_message_for_should do |block| "expected exit with code #{expected} but " + (actual.nil? ? " exit was not called" : "we exited with #{actual} instead") end failure_message_for_should_not do |block| "expected that exit would not be called with #{expected}" end description do "expect exit with #{expected}" end end RSpec::Matchers.define :have_printed do |expected| match do |block| $stderr = $stdout = StringIO.new begin block.call ensure $stdout.rewind @actual = $stdout.read $stdout = STDOUT $stderr = STDERR end if @actual then case expected when String @actual.include? expected when Regexp expected.match @actual else raise ArgumentError, "No idea how to match a #{@actual.class.name}" end end end failure_message_for_should do |actual| if actual.nil? then "expected #{expected.inspect}, but nothing was printed" else "expected #{expected.inspect} to be printed; got:\n#{actual}" end end description do "expect #{expected.inspect} to be printed" end diffable end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb000066400000000000000000000053231324035536100326660ustar00rootroot00000000000000# Initialize puppet for testing by loading the # 'puppetlabs_spec_helper/puppet_spec_helper' library require 'puppetlabs_spec_helper/puppet_spec_helper' module PuppetlabsSpec module 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 Puppet.version =~ /^2\.[67]/ # 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_resource = parts[:resource] || resource(:type => :node, :title => scope_compiler.node.name) if Puppet.version =~ /^2\.[67]/ scope = Puppet::Parser::Scope.new(:compiler => scope_compiler) else scope = 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" Puppet::Resource::Type.new(resource_type, resource_name) end module_function :resource def compiler(parts = {}) compiler_node = parts[:node] || node() Puppet::Parser::Compiler.new(compiler_node) end module_function :compiler def node(parts = {}) node_name = parts[:name] || 'testinghost' options = parts[:options] || {} 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 module_function :node # Return a method instance for a given function. This is primarily useful # for rspec-puppet def function_method(name, parts = {}) scope = parts[:scope] || scope() # Ensure the method instance is defined by side-effect of checking if it # exists. This is a hack, but at least it's a hidden hack and not an # exposed hack. return nil unless Puppet::Parser::Functions.function(name) scope.method("function_#{name}".intern) end module_function :function_method end end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb000066400000000000000000000020151324035536100306240ustar00rootroot00000000000000# Define the main module namespace for use by the helper modules module PuppetlabsSpec # FIXTURE_DIR represents the standard locations of all fixture data. Normally # this represents /spec/fixtures. This will be used by the fixtures # library to find relative fixture data. FIXTURE_DIR = File.join("spec", "fixtures") unless defined?(FIXTURE_DIR) end # Require all necessary helper libraries so they can be used later require 'puppetlabs_spec_helper/puppetlabs_spec/files' require 'puppetlabs_spec_helper/puppetlabs_spec/fixtures' require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals' require 'puppetlabs_spec_helper/puppetlabs_spec/matchers' RSpec.configure do |config| # Include PuppetlabsSpec helpers so they can be called at convenience config.extend PuppetlabsSpec::Files config.extend PuppetlabsSpec::Fixtures config.include PuppetlabsSpec::Fixtures # This will cleanup any files that were created with tmpdir or tmpfile config.after :each do PuppetlabsSpec::Files.cleanup end end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/rake_tasks.rb000066400000000000000000000520521324035536100262310ustar00rootroot00000000000000require 'fileutils' require 'rake' require 'rspec/core/rake_task' require 'tmpdir' require 'yaml' require 'pathname' require 'puppetlabs_spec_helper/version' # optional gems begin require 'metadata-json-lint/rake_task' rescue LoadError # ignore end parallel_tests_loaded = false begin require 'parallel_tests' parallel_tests_loaded = true rescue LoadError # ignore end task :default => [:help] pattern = 'spec/{aliases,classes,defines,unit,functions,hosts,integration,type_aliases,types}/**/*_spec.rb' RSpec::Core::RakeTask.new(:spec_standalone) do |t, args| t.rspec_opts = ['--color'] t.rspec_opts << ENV['CI_SPEC_OPTIONS'] unless ENV['CI_SPEC_OPTIONS'].nil? if ENV['CI_NODE_TOTAL'] && ENV['CI_NODE_INDEX'] ci_total = ENV['CI_NODE_TOTAL'].to_i ci_index = ENV['CI_NODE_INDEX'].to_i raise "CI_NODE_INDEX must be between 1-#{ci_total}" unless ci_index >= 1 && ci_index <= ci_total files = Rake::FileList[pattern].to_a per_node = (files.size / ci_total.to_f).ceil t.pattern = if args.extras.nil? || args.extras.empty? files.each_slice(per_node).to_a[ci_index - 1] || files.first else args.extras.join(",") end else if args.extras.nil? || args.extras.empty? t.pattern = pattern else t.pattern = args.extras.join(",") end end end desc "List spec tests in a JSON document" RSpec::Core::RakeTask.new(:spec_list_json) do |t| t.rspec_opts = ['--dry-run', '--format', 'json'] t.pattern = pattern end desc "Run beaker acceptance tests" RSpec::Core::RakeTask.new(:beaker) do |t| t.rspec_opts = ['--color'] t.pattern = 'spec/acceptance' # TEST_TIERS env variable is a comma separated list of tiers to run. e.g. low, medium, high if ENV['TEST_TIERS'] tiers = '--tag ' test_tiers = ENV['TEST_TIERS'].split(',') raise 'TEST_TIERS env variable must have at least 1 tier specified. low, medium or high (comma separated).' if test_tiers.count == 0 test_tiers.each do |tier| tier_to_add = tier.strip raise "#{tier_to_add} not a valid test tier." unless %w(low medium high).include?(tier_to_add) tiers += "tier_#{tier_to_add}," end tiers = tiers.chomp(',') t.rspec_opts.push(tiers) else puts 'TEST_TIERS env variable not defined. Defaulting to run all tests.' end end module PuppetlabsSpecHelper::RakeTasks # This is a helper for the self-symlink entry of fixtures.yml def source_dir Dir.pwd end # cache the repositories and return a hash object def repositories unless @repositories @repositories = fixtures('repositories') end @repositories end # get the array of Beaker set names # @return [Array] def beaker_node_sets return @beaker_nodes if @beaker_nodes @beaker_nodes = Dir['spec/acceptance/nodesets/*.yml'].sort.map do |node_set| node_set.slice!('.yml') File.basename(node_set) end end # Use "vagrant ssh" to login to the given node in the node set # @param set [String] The name of the node set (yml file) # @param node [String] The name of the node in the set. For multi-node sets. def vagrant_ssh(set, node = nil) vagrant_yml_dir = File.join '.vagrant', 'beaker_vagrant_files', "#{set}.yml" vagrant_file = File.join vagrant_yml_dir, 'Vagrantfile' unless File.file? vagrant_file puts "There is no Vagrantfile at: '#{vagrant_file}'. Perhaps, the node is not created or is destroyed." exit 1 end Dir.chdir(vagrant_yml_dir) do command = 'vagrant ssh' command += " #{node}" if node # Vagrant is not distributed as a normal gem # and we should protect it from the current Ruby environment env = { 'RUBYLIB' => nil, 'GEM_PATH' => nil, 'BUNDLE_BIN_PATH' => nil, } system env, command end end def auto_symlink { File.basename(Dir.pwd).split('-').last => '#{source_dir}' } end def fixtures(category) if ENV['FIXTURES_YML'] fixtures_yaml = ENV['FIXTURES_YML'] elsif File.exists?('.fixtures.yml') fixtures_yaml = '.fixtures.yml' elsif File.exists?('.fixtures.yaml') fixtures_yaml = '.fixtures.yaml' else fixtures_yaml = false end begin if fixtures_yaml fixtures = YAML.load_file(fixtures_yaml) || { 'fixtures' => {} } else fixtures = { 'fixtures' => {} } end rescue Errno::ENOENT fail("Fixtures file not found: '#{fixtures_yaml}'") rescue Psych::SyntaxError => e fail("Found malformed YAML in '#{fixtures_yaml}' on line #{e.line} column #{e.column}: #{e.problem}") end unless fixtures.include?('fixtures') # File is non-empty, but does not specify fixtures fail("No 'fixtures' entries found in '#{fixtures_yaml}'; required") end if fixtures.include? 'defaults' fixture_defaults = fixtures['defaults'] else fixture_defaults = {} end fixtures = fixtures['fixtures'] if fixtures['symlinks'].nil? fixtures['symlinks'] = auto_symlink end result = {} if fixtures.include? category and fixtures[category] != nil defaults = { "target" => "spec/fixtures/modules" } # load defaults from the `.fixtures.yml` `defaults` section # for the requested category and merge them into my defaults if fixture_defaults.include? category defaults = defaults.merge(fixture_defaults[category]) end fixtures[category].each do |fixture, opts| # convert a simple string fixture to a hash, by # using the string fixture as the `repo` option of the hash. if opts.instance_of?(String) opts = { "repo" => opts } end # there should be a warning or something if it's not a hash... if opts.instance_of?(Hash) # merge our options into the defaults to get the # final option list opts = defaults.merge(opts) real_target = eval('"'+opts["target"]+'"') real_source = eval('"'+opts["repo"]+'"') result[real_source] = { "target" => File.join(real_target,fixture), "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"], "flags" => opts["flags"], "subdir" => opts["subdir"]} end end end return result end def clone_repo(scm, remote, target, subdir=nil, ref=nil, branch=nil, flags = nil) args = [] case scm when 'hg' args.push('clone') args.push('-b', branch) if branch args.push(flags) if flags args.push(remote, target) when 'git' args.push('clone') args.push('--depth 1') unless ref args.push('-b', branch) if branch args.push(flags) if flags args.push(remote, target) else fail "Unfortunately #{scm} is not supported yet" end result = system("#{scm} #{args.flatten.join ' '}") unless File::exists?(target) fail "Failed to clone #{scm} repository #{remote} into #{target}" end result 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 def remove_subdirectory(target, subdir) unless subdir.nil? Dir.mktmpdir {|tmpdir| FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir) FileUtils.rm_rf("#{target}/#{subdir}") FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), "#{target}") } end end # creates a logger so we can log events with certain levels def logger unless @logger require 'logger' if ENV['ENABLE_LOGGER'] level = Logger::DEBUG else level = Logger::INFO end @logger = Logger.new(STDERR) @logger.level = level end @logger end def module_working_directory # The problem with the relative path is that PMT doesn't expand the path properly and so passing in a relative path here # becomes something like C:\somewhere\backslashes/spec/fixtures/work-dir on Windows, and then PMT barfs itself. # This has been reported as https://tickets.puppetlabs.com/browse/PUP-4884 File.expand_path(ENV['MODULE_WORKING_DIR'] ? ENV['MODULE_WORKING_DIR'] : 'spec/fixtures/work-dir') end # returns the current thread count that is currently active # a status of false or nil means the thread completed # so when anything else we count that as a active thread def current_thread_count(items) active_threads = items.find_all do |item, opts| if opts[:thread] opts[:thread].status else false end end logger.debug "Current thread count #{active_threads.count}" active_threads.count end # returns the max_thread_count # because we may want to limit ssh or https connections def max_thread_limit unless @max_thread_limit # the default thread count is 10 but can be # raised by using environment variable MAX_FIXTURE_THREAD_COUNT if ENV['MAX_FIXTURE_THREAD_COUNT'].to_i > 0 @max_thread_limit = ENV['MAX_FIXTURE_THREAD_COUNT'].to_i else @max_thread_limit = 10 # the default end end @max_thread_limit end def check_directory_for_symlinks(dir='.') dir = Pathname.new(dir) unless dir.is_a?(Pathname) results = [] dir.each_child(true) do |child| if child.symlink? results << child elsif child.directory? && child.basename.to_s != '.git' results.concat(check_directory_for_symlinks(child)) end end results end end include PuppetlabsSpecHelper::RakeTasks 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 if is_windows begin require 'win32/dir' rescue LoadError $stderr.puts "win32-dir gem not installed, falling back to executing mklink directly" end end # git has a race condition creating that directory, that would lead to aborted clone operations FileUtils::mkdir_p("spec/fixtures/modules") repositories.each do |remote, opts| scm = 'git' target = opts["target"] subdir = opts["subdir"] ref = opts["ref"] scm = opts["scm"] if opts["scm"] branch = opts["branch"] if opts["branch"] flags = opts["flags"] # get the current active threads that are alive count = current_thread_count(repositories) if count < max_thread_limit logger.debug "New Thread started for #{remote}" # start up a new thread and store it in the opts hash opts[:thread] = Thread.new do clone_repo(scm, remote, target, subdir, ref, branch, flags) revision(scm, target, ref) if ref remove_subdirectory(target, subdir) if subdir end else # the last thread started should be the longest wait item, item_opts = repositories.find_all {|i,o| o.has_key?(:thread)}.last logger.debug "Waiting on #{item}" item_opts[:thread].join # wait for the thread to finish # now that we waited lets try again redo end end # wait for all the threads to finish repositories.each {|remote, opts| opts[:thread].join } fixtures("symlinks").each do |target, link| link = link['target'] unless File.symlink?(link) logger.info("Creating symlink from #{link} to #{target}") if is_windows target = File.join(File.dirname(link), target) unless Pathname.new(target).absolute? if Dir.respond_to?(:create_junction) Dir.create_junction(link, target) else system("call mklink /J \"#{link.gsub('/', '\\')}\" \"#{target.gsub('/', '\\')}\"") end else FileUtils::ln_sf(target, link) end end end fixtures("forge_modules").each do |remote, opts| ref = "" flags = "" if opts.instance_of?(String) target = opts elsif opts.instance_of?(Hash) target = opts["target"] ref = " --version #{opts['ref']}" if not opts['ref'].nil? flags = " #{opts['flags']}" if opts['flags'] end next if File::exists?(target) working_dir = module_working_directory target_dir = File.expand_path('spec/fixtures/modules') command = "puppet module install" + ref + flags + \ " --ignore-dependencies" \ " --force" \ " --module_working_dir \"#{working_dir}\"" \ " --target-dir \"#{target_dir}\" \"#{remote}\"" unless system(command) fail "Failed to install module #{remote} to #{target_dir}" end end FileUtils::mkdir_p("spec/fixtures/manifests") FileUtils::touch("spec/fixtures/manifests/site.pp") end desc "Clean up the fixtures directory" task :spec_clean do fixtures("repositories").each do |remote, opts| target = opts["target"] FileUtils::rm_rf(target) end fixtures("forge_modules").each do |remote, opts| target = opts["target"] FileUtils::rm_rf(target) end FileUtils::rm_rf(module_working_directory) fixtures("symlinks").each do |source, opts| target = opts["target"] FileUtils::rm_f(target) end if File.zero?("spec/fixtures/manifests/site.pp") FileUtils::rm_f("spec/fixtures/manifests/site.pp") end end desc "Run spec tests and clean the fixtures directory if successful" task :spec do |t, args| begin Rake::Task[:spec_prep].invoke Rake::Task[:spec_standalone].invoke(*args.extras) ensure Rake::Task[:spec_clean].invoke end end desc "Parallel spec tests" task :parallel_spec do raise 'Add the parallel_tests gem to Gemfile to enable this task' unless parallel_tests_loaded if Rake::FileList[pattern].to_a.empty? warn "No files for parallel_spec to run against" else begin args = ['-t', 'rspec'] args.push('--').concat(ENV['CI_SPEC_OPTIONS'].strip.split(' ')).push('--') unless ENV['CI_SPEC_OPTIONS'].nil? || ENV['CI_SPEC_OPTIONS'].strip.empty? args.concat(Rake::FileList[pattern].to_a) Rake::Task[:spec_prep].invoke ParallelTests::CLI.new.run(args) ensure Rake::Task[:spec_clean].invoke end end end desc "List available beaker nodesets" task 'beaker:sets' do beaker_node_sets.each do |set| puts set end end # alias for compatibility task 'beaker_nodes' => 'beaker:sets' desc 'Try to use vagrant to login to the Beaker node' task 'beaker:ssh', [:set, :node] do |_task, args| set = args[:set] || ENV['BEAKER_set'] || ENV['RS_SET'] || 'default' node = args[:node] vagrant_ssh set, node end beaker_node_sets.each do |set| desc "Run the Beaker acceptance tests for the node set '#{set}'" task "beaker:#{set}" do ENV['BEAKER_set'] = set Rake::Task['beaker'].reenable Rake::Task['beaker'].invoke end desc "Use vagrant to login to a node from the set '#{set}'" task "beaker:ssh:#{set}", [:node] do |_task, args| node = args[:node] vagrant_ssh set, node end end desc "Build puppet module package" task :build do # This will be deprecated once puppet-module is a face. begin Gem::Specification.find_by_name('puppet-module') rescue Gem::LoadError, NoMethodError require 'puppet/face' pmod = Puppet::Face['module', :current] pmod.build('./') end end desc "Clean a built module package" task :clean do FileUtils.rm_rf("pkg/") end 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', '140chars', 'class_inherits_from_params_class', 'class_parameter_defaults', 'documentation', 'single_quote_string_with_variables'] config.ignore_paths = [ "bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp", ] end require 'puppet-syntax/tasks/puppet-syntax' PuppetSyntax.exclude_paths ||= [] PuppetSyntax.exclude_paths << "spec/fixtures/**/*" PuppetSyntax.exclude_paths << "pkg/**/*" PuppetSyntax.exclude_paths << "vendor/**/*" if Puppet.version.to_f < 4.0 PuppetSyntax.exclude_paths << "types/**/*" end PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'yes' desc "Check syntax of Ruby files and call :syntax and :metadata_lint" task :validate do Dir['lib/**/*.rb'].each do |lib_file| sh "ruby -c #{lib_file}" end Rake::Task[:syntax].invoke if File.exist?('metadata.json') 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 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 = '' if File.exists?( 'metadata.json' ) require 'json' modinfo = JSON.parse(File.read( 'metadata.json' )) version = modinfo['version'] elsif File.exists?( 'Modulefile' ) modfile = File.read('Modulefile') version = modfile.match(/\nversion[ ]+['"](.*)['"]/)[1] else fail "Could not find a metadata.json or Modulefile! Cannot compute dev version without one or the other!" end sha = `git rev-parse HEAD`[0..7] branch = `git rev-parse --abbrev-ref HEAD` # If we're in a CI environment include our build number # 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 master branch when trying to push to the staging forge. # More info can be found at https://tickets.puppetlabs.com/browse/FM-6170 if build = ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER'] if branch.eql? "release" new_version = sprintf('%s-%s%04d-%s', version, "r", build, sha) else new_version = sprintf('%s-%04d-%s', version, build, sha) end else new_version = "#{version}-#{sha}" end print new_version end desc "Runs all necessary checks on a module in preparation for a release" task :release_checks do Rake::Task[:lint].invoke Rake::Task[:validate].invoke if parallel_tests_loaded Rake::Task[:parallel_spec].invoke else Rake::Task[:spec].invoke end Rake::Task["check:symlinks"].invoke Rake::Task["check:test_file"].invoke Rake::Task["check:dot_underscore"].invoke Rake::Task["check:git_ignore"].invoke end namespace :check do desc "Fails if symlinks are present in directory" task :symlinks do symlinks = check_directory_for_symlinks unless symlinks.empty? symlinks.each { |r| puts "Symlink found: #{r.to_s} => #{r.readlink}" } fail "Symlink(s) exist within this directory" end end desc "Fails if .pp files present in tests folder" task :test_file do if Dir.exist?("tests") Dir.chdir("tests") ppfiles = Dir["*.pp"] unless ppfiles.empty? puts ppfiles fail ".pp files present in tests folder; Move them to an examples folder following the new convention" end end end desc "Fails if any ._ files are present in directory" task :dot_underscore do dirs = Dir["._*"] unless dirs.empty? puts dirs fail "._ files are present in the directory" end end desc "Fails if directories contain the files specified in .gitignore" task :git_ignore do matched = `git ls-files --ignored --exclude-standard` unless matched == "" puts matched fail "File specified in .gitignore has been committed" end end end desc "Display the list of available rake tasks" task :help do system("rake -T") end begin require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) do |task| # These make the rubocop experience maybe slightly less terrible task.options = ['-D', '-S', '-E'] end rescue LoadError desc "rubocop is not available in this installation" task :rubocop do fail "rubocop is not available in this installation" end end module_dir = Dir.pwd locales_dir = File.absolute_path('locales', module_dir ) # if the task is allowed to run when the module does not have a locales directory, # the task is run in the puppet gem instead and creates a POT there. puts "gettext-setup tasks will only be loaded if the locales/ directory is present" if Rake.verbose == true if File.exist? locales_dir begin spec = Gem::Specification.find_by_name 'gettext-setup' load "#{spec.gem_dir}/lib/tasks/gettext.rake" # Initialization requires a valid locales directory GettextSetup.initialize_config(locales_dir) namespace :module do desc "Runs all tasks to build a modules POT file for internationalization" task :pot_gen do Rake::Task["gettext:pot"].invoke() Rake::Task["gettext:metadata_pot"].invoke("#{module_dir}/metadata.json") end end rescue Gem::LoadError puts "No gettext-setup gem found, skipping GettextSetup config initialization" if Rake.verbose == true end end puppetlabs_spec_helper-2.6.2/lib/puppetlabs_spec_helper/version.rb000066400000000000000000000002421324035536100255610ustar00rootroot00000000000000module PuppetlabsSpecHelper VERSION = "2.6.2" # compat for pre-1.2.0 users; deprecated module Version STRING = PuppetlabsSpecHelper::VERSION end end puppetlabs_spec_helper-2.6.2/puppet_spec_helper.rb000066400000000000000000000004221324035536100224640ustar00rootroot00000000000000$:.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" puppetlabs_spec_helper-2.6.2/puppetlabs_spec_helper.gemspec000066400000000000000000000027211324035536100243520ustar00rootroot00000000000000# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'puppetlabs_spec_helper/version' Gem::Specification.new do |spec| spec.name = "puppetlabs_spec_helper" spec.version = PuppetlabsSpecHelper::VERSION spec.authors = ["Puppet, Inc.", "Community Contributors"] spec.email = ["modules-team@puppet.com"] spec.summary = %q{Standard tasks and configuration for module spec tests.} spec.description = %q{Contains rake tasks and a standard spec_helper for running spec tests on puppet modules.} spec.homepage = "http://github.com/puppetlabs/puppetlabs_spec_helper" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_runtime_dependency "mocha", "~> 1.0" spec.add_runtime_dependency "puppet-lint", "~> 2.0" spec.add_runtime_dependency "puppet-syntax", "~> 2.0" spec.add_runtime_dependency "rspec-puppet", "~> 2.0" spec.add_development_dependency "bundler", "~> 1.12" spec.add_development_dependency "pry" spec.add_development_dependency "puppet" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "yard" spec.add_development_dependency "gettext-setup", "~> 0.29" end puppetlabs_spec_helper-2.6.2/puppetlabs_spec_helper.rb000066400000000000000000000004361324035536100233330ustar00rootroot00000000000000$:.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" puppetlabs_spec_helper-2.6.2/spec/000077500000000000000000000000001324035536100172055ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/spec/spec_helper.rb000066400000000000000000000000001324035536100220110ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/spec/unit/000077500000000000000000000000001324035536100201645ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/spec/unit/puppetlabs_spec_helper/000077500000000000000000000000001324035536100247145ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/spec/unit/puppetlabs_spec_helper/puppetlabs_spec/000077500000000000000000000000001324035536100301055ustar00rootroot00000000000000puppet_internals_spec.rb000066400000000000000000000056621324035536100347720ustar00rootroot00000000000000puppetlabs_spec_helper-2.6.2/spec/unit/puppetlabs_spec_helper/puppetlabs_specrequire 'spec_helper' require 'puppetlabs_spec_helper/puppet_spec_helper' require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals' # reset mock integration RSpec.configure do |c| c.mock_with :rspec end describe PuppetlabsSpec::PuppetInternals do before(:all) do Puppet.initialize_settings end describe '.scope' do let(:subject) { described_class.scope } it 'should return a Puppet::Parser::Scope instance' do expect(subject).to be_a_kind_of Puppet::Parser::Scope end it 'should be suitable for function testing' do expect(subject.function_inline_template(['foo'])).to eq('foo') end it 'should accept a compiler' do compiler = described_class.compiler scope = described_class.scope(compiler: compiler) expect(scope.compiler).to eq(compiler) end it 'should have a source set' do scope = subject expect(scope.source).not_to be_nil expect(scope.source.name).to eq('foo') end end describe '.resource' do let(:subject) { described_class.resource } it 'can have a defined type' do expect(described_class.resource(type: :node).type).to eq(:node) end it 'defaults to a type of hostclass' do expect(subject.type).to eq(:hostclass) end it 'can have a defined name' do expect(described_class.resource(name: 'testingrsrc').name).to eq('testingrsrc') end it 'defaults to a name of testing' do expect(subject.name).to eq('testing') end end describe '.compiler' do let(:node) { described_class.node } it 'can have a defined node' do expect(described_class.compiler(node: node).node).to be node end end describe '.node' do it 'can have a defined name' do expect(described_class.node(name: 'mine').name).to eq('mine') end it 'can have a defined environment' do expect(described_class.node(environment: 'mine').environment.name).to eq(:mine) end it 'defaults to a name of testinghost' do expect(described_class.node.name).to eq('testinghost') end it 'accepts facts via options for rspec-puppet' do fact_values = { 'fqdn' => 'jeff.puppetlabs.com' } node = described_class.node(options: { parameters: fact_values }) expect(node.parameters).to eq(fact_values) end end describe '.function_method' do it 'accepts an injected scope' do expect(Puppet::Parser::Functions).to receive(:function).with('my_func').and_return(true) scope = double(described_class.scope) scope.expects(:method).with(:function_my_func).returns(:fake_method) expect(described_class.function_method('my_func', scope: scope)).to eq(:fake_method) end it "returns nil if the function doesn't exist" do Puppet::Parser::Functions.expects(:function).with('my_func').returns(false) scope = double(described_class.scope) expect(described_class.function_method('my_func', scope: scope)).to be_nil end end end puppetlabs_spec_helper-2.6.2/spec/unit/puppetlabs_spec_helper/rake_task_spec.rb000066400000000000000000000072231324035536100302230ustar00rootroot00000000000000require 'puppetlabs_spec_helper/puppet_spec_helper' require 'puppetlabs_spec_helper/rake_tasks' RSpec.configure do |config| config.mock_with :rspec config.include PuppetlabsSpecHelper::RakeTasks end describe PuppetlabsSpecHelper::RakeTasks do describe '.fixtures' do before :each do # Unstub the fixtures "helpers" PuppetlabsSpec::Fixtures.instance_methods.each do |m| PuppetlabsSpec::Fixtures.send(:undef_method, m) end allow(File).to receive(:exists?).with('.fixtures.yml').and_return false allow(File).to receive(:exists?).with('.fixtures.yaml').and_return false allow(ENV).to receive(:[]).and_call_original allow(ENV).to receive(:[]).with('FIXTURES_YML').and_return(nil) allow(PuppetlabsSpecHelper::RakeTasks).to receive(:auto_symlink).and_return({ 'project' => '#{source_dir}' }) end context 'when file is missing' do it 'returns basic directories per category' do expect(subject.fixtures("forge_modules")).to eq({}) expect(subject.fixtures("repositories")).to eq({}) end end context 'when file is empty' do it 'returns basic directories per category' do allow(File).to receive(:exists?).with('.fixtures.yml').and_return true allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return false expect(subject.fixtures("forge_modules")).to eq({}) expect(subject.fixtures("repositories")).to eq({}) end end context 'when file is malformed' do it 'raises an error' do allow(File).to receive(:exists?).with('.fixtures.yml').and_return true allow(YAML).to receive(:load_file).with('.fixtures.yml').and_raise(Psych::SyntaxError.new('/file', '123', '0', '0', 'spec message', 'spec context')) expect { subject.fixtures("forge_modules") }.to raise_error(RuntimeError, /malformed YAML/) end end context 'when file contains no fixtures' do it 'raises an error' do allow(File).to receive(:exists?).with('.fixtures.yml').and_return true allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return({'some' => 'key'}) expect { subject.fixtures("forge_modules") }.to raise_error(RuntimeError, /No 'fixtures'/) end end context 'when file specifies fixtures' do it 'returns the hash' do allow(File).to receive(:exists?).with('.fixtures.yml').and_return true allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return({'fixtures' => { 'forge_modules' => { 'stdlib' => 'puppetlabs-stdlib'}}}) expect(subject.fixtures("forge_modules")).to eq({ 'puppetlabs-stdlib' => { 'target' => 'spec/fixtures/modules/stdlib', 'ref' => nil, 'branch' => nil, 'scm' => nil, 'flags' => nil, 'subdir' => nil, } }) end end context 'when file specifies defaults' do it 'returns the hash' do allow(File).to receive(:exists?).with('.fixtures.yml').and_return true allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return({ 'defaults' => { 'forge_modules' => { 'flags' => '--module_repository=https://myforge.example.com/' }}, 'fixtures' => { 'forge_modules' => { 'stdlib' => 'puppetlabs-stdlib'}}}) expect(subject.fixtures("forge_modules")).to eq({ 'puppetlabs-stdlib' => { 'target' => 'spec/fixtures/modules/stdlib', 'ref' => nil, 'branch' => nil, 'scm' => nil, 'flags' => '--module_repository=https://myforge.example.com/', 'subdir' => nil, } }) end end end end puppetlabs_spec_helper-2.6.2/spec/watchr.rb000066400000000000000000000031411324035536100210210ustar00rootroot00000000000000ENV['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 @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