GithubHelp home page GithubHelp logo

optionalg / puppetlabs_spec_helper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from puppetlabs/puppetlabs_spec_helper

0.0 3.0 0.0 241 KB

A set of shared spec helpers specific to Puppetlabs projects

License: Other

puppetlabs_spec_helper's Introduction

Puppet Labs Spec Helper

The Short Version

This repository is meant to provide a single source of truth for how to initialize different Puppet versions for spec testing.

The common use case is a module such as stdlib 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:

Usage

When developing or testing modules, simply clone this repository and install the gem it contains.

$ git clone git://github.com/puppetlabs/puppetlabs_spec_helper.git
$ cd puppetlabs_spec_helper
$ rake package:gem
$ gem install pkg/puppetlabs_spec_helper-*.gem

Add this to your project's spec_helper.rb:

require 'rubygems'
require 'puppetlabs_spec_helper/module_spec_helper'

Add this to your project's Rakefile:

require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'

And run the spec tests:

$ cd $modulename
$ rake spec

Issues

Please file issues against this project at the Puppet Labs Issue Tracker

The Long Version

Purpose of this Project

This project is intended to serve two purposes:

  1. To serve as a bridge between external projects and multiple versions of puppet; in other words, if your project has a dependency on puppet, you shouldn't need to need to worry about the details of how to initialize puppet's state for testing, no matter what version of puppet you are testing against.
  2. To provide some convenience classes / methods for doing things like creating tempfiles, common rspec matchers, etc. These classes are in the puppetlabs_spec directory.
  3. To provide a common set of Rake tasks so that the procedure for testing modules is unified.

To Use this Project

The most common usage scenario is that you will check out the 'master' branch of this project from github, and install it as a rubygem. There should be few or no cases where you would want to have any other branch of this project besides master/HEAD.

Initializing Puppet for Testing

In most cases, your project should be able to define a spec_helper.rb that includes just this one simple line:

require 'puppetlabs_spec_helper/puppet_spec_helper'

Then, as long as the gem is installed, you should be all set.

If you are using rspec-puppet for module testing, you will want to include a different library:

require 'puppetlabs_spec_helper/module_spec_helper'

NOTE that this is specifically for initializing Puppet's core. If your project does not have any dependencies on puppet and you just want to use the utility classes, see the next section.

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.

Fixtures Examples

Basic fixtures that will symlink spec/fixtures/modules/my_modules to the project root:

fixtures:
  symlinks:
    my_module: "#{source_dir}"

Add firewall and stdlib as required module fixtures:

fixtures:
  repositories:
    firewall: "git://github.com/puppetlabs/puppetlabs-firewall"
    stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib"
  symlinks:
    my_module: "#{source_dir}"

Specify that the git tag 2.4.2 of `stdlib' should be checked out:

fixtures:
  repositories:
    firewall: "git://github.com/puppetlabs/puppetlabs-firewall"
    stdlib:
      repo: "git://github.com/puppetlabs/puppetlabs-stdlib"
      ref: "2.6.0"
  symlinks:
    my_module: "#{source_dir}"

Testing Parser Functions

This library provides a consistent way to create a Puppet::Parser::Scope object suitable for use in a testing harness with the intent of testing the expected behavior of parser functions distributed in modules.

Previously, modules would do something like this:

describe "split()" do
  let(:scope) { Puppet::Parser::Scope.new }
  it "should split 'one;two' on ';' into [ 'one', 'two' ]" do
    scope.function_split(['one;two', ';']).should == [ 'one', 'two' ]
  end
end

This will not work beyond Puppet 2.7 as we have changed the behavior of the scope initializer in Puppet 3.0. Modules should instead initialize scope instances in a manner decoupled from the internal behavior of Puppet:

require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
describe "split()" do
  let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
  it "should split 'one;two' on ';' into [ 'one', 'two' ]" do
    scope.function_split(['one;two', ';']).should == [ 'one', 'two' ]
  end
end

EOF

puppetlabs_spec_helper's People

Contributors

hunner avatar cprice404 avatar haus avatar joshcooper avatar justinstoller avatar bodepd avatar zaphod42 avatar adrienthebo avatar igalic avatar mafalb avatar davids avatar djm68 avatar fatmcgav avatar kbarber avatar mitchellh avatar nanliu avatar pabelanger avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.