Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
(SIMP-3430) Create Centralize spec_helpers.rb
Browse files Browse the repository at this point in the history
- created baseline for spec_helper.rb
  to do basc RSPEC configuration for SIMP module unit tests.
- added some basic methods that were also in spec_helpers
- added compliance markup methods for use in compliance
  markup unit tests.

SIMP-3430 #comment added simp-spec-helpers
  • Loading branch information
jeannegreulich committed Jan 27, 2020
1 parent 1c225e0 commit aa608a7
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 291 deletions.
22 changes: 22 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# SIMP_GEM_SERVERS | a space/comma delimited list of rubygem servers
# PUPPET_VERSION | specifies the version of the puppet gem to load
# FACTER_GEM_VERSION | specifies the version of the facter to load
puppetversion = ENV.fetch('PUPPET_VERSION', '~> 5.5')
gem_sources = ENV.key?('SIMP_GEM_SERVERS') ? ENV['SIMP_GEM_SERVERS'].split(/[, ]+/) : ['https://rubygems.org']

gem_sources.each { |gem_source| source gem_source }

gemspec

gem 'puppet', puppetversion, :require => false

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
end

group :test do
gem 'rspec'
gem 'puppetlabs_spec_helper'
end

149 changes: 149 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,151 @@
# rubygem-simp-spec-helpers

rspec-puppet helper methods for SIMP module testing

imp-rake-helpers

[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
[![Build Status](https://travis-ci.org/simp/rubygem-simp-rake-helpers.svg?branch=master)](https://travis-ci.org/simp/rubygem-simp-rake-helpers)
[![Gem](https://img.shields.io/gem/v/simp-rake-helpers.svg)](https://rubygems.org/gems/simp-rake-helpers)
[![Gem_Downloads](https://img.shields.io/gem/dt/simp-rake-helpers.svg)](https://rubygems.org/gems/simp-rake-helpers)

#### Table of Contents

<!-- vim-markdown-toc GFM -->

* [Overview](#overview)
* [This gem is part of SIMP](#this-gem-is-part-of-simp)
* [Features](#features)
* [Setup](#setup)
* [Gemfile](#gemfile)
* [Usage](#usage)
* [In a Puppet module](#in-a-puppet-module)
* [Environment Variables](#environment-variables)
* [In a Ruby Gem](#in-a-ruby-gem)
* [Generating RPMs](#generating-rpms)
* [RPM Changelog](#rpm-changelog)
* [RPM Dependencies](#rpm-dependencies)
* [Reference](#reference)
* [simp/rake/rpm](#simprakerpm)
* [`rake pkg:rpm`](#rake-pkgrpm)
* [`rake pkg:tar`](#rake-pkgtar)
* [Limitations](#limitations)
* [Some versions of bundler fail on FIPS-enabled Systems](#some-versions-of-bundler-fail-on-fips-enabled-systems)
* [Development](#development)
* [License](#license)
* [History](#history)

<!-- vim-markdown-toc -->

## Overview

The `simp-rake-helpers` gem provides common Rake tasks to support the SIMP build process.

### This gem is part of SIMP

This gem is part of (the build tooling for) the [System Integrity Management Platform](https://github.com/NationalSecurityAgency/SIMP), a complian
ce-management framework built on [Puppet](https://puppetlabs.com/).


### Features

* Customizable RPM packaging based on a Puppet module's [`metadata.json`][metadata.json]
* RPM signing
* Rubygem packaging

## Setup


### Gemfile

group :test do
gem 'puppet', 'puppet', ENV.fetch('PUPPET_VERSION', '~> 5.5')
gem 'rspec'
gem 'rspec-puppet'
gem 'hiera-puppet-helper'
gem 'puppetlabs_spec_helper'
gem 'metadata-json-lint'
gem 'puppet-strings'
gem 'simp-spec-helpers'
gem 'simp-rspec-puppet-facts', ENV.fetch('SIMP_RSPEC_PUPPET_FACTS_VERSION', '~> 2.2')
gem 'simp-rake-helpers', ENV.fetch('SIMP_RAKE_HELPERS_VERSION', '~> 5.9')
gem 'facterdb'
end

## Usage


To include the helpers and run the basic rspec configuration put the following in your spec/spec_helper.rb

``` ruby
require 'simp/rspec-puppet-facts'
include Simp::RspecPuppetFacts
require 'simp/spec_helpers'
include Simp::SpecHelpers
require 'pathname'

# Put any local methods in spec_helper_local.rb
require_relative 'spec_helper_local' if File.exists?("./spec_helper_local.rb")

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
module_name = File.basename(File.expand_path(File.join(__FILE__,'../..')))

global_spec_helper(fixture_path, module_name)
```
and then at the top of the test file:

```ruby
require 'spec_helper'
```
### Environment Variables

PUPPET_DEBUG set to anything will enable debug

SIMP_RSPEC_MOCK_ENV The mock_with setting in rspec is defaulted to mocha
in these helpers. to use rspec to mock set this to "rspec"

### Available methods

Besides the global_spec_helper that is used to set up rspec the following
methods are installed and can be used in your tests:


#### set_hieradata(hieradata)
This can be used from inside your spec tests to load custom hieradata within
any context.

Example:

describe 'some::class' do
context 'with version 10' do
let(:hieradata){ "#{class_name}_v10" }
...
end
end

Then, create a YAML file at spec/fixtures/hieradata/some__class_v10.yaml.

Hiera will use this file as it's base of information stacked on top of
'default.yaml' and <module_name>.yaml per the defaults above.

Note: Any colons (:) are replaced with underscores (_) in the class name.


#### set_environment
This can be used from inside your spec tests to set the testable environment.
You can use this to stub out an ENC.

Example:

context 'in the :foo environment' do
let(:environment){:foo}
...
end


#### normalize_compliance_results
Can be used to removed expected errors in compliance data due to test configuration.
See pupmod-simp-pupmod for example.



32 changes: 0 additions & 32 deletions lib/simp/rake/spec.rb

This file was deleted.

Loading

0 comments on commit aa608a7

Please sign in to comment.