Giter Site home page Giter Site logo

rspec-chef's Introduction

RSpec matchers and examples for your Chef recipes

Test your Chef cookbooks nicely.

This project is heavily inspired by RSpec-puppet.

Installation

gem install rspec-chef

Example groups

Recipes

Follow this structure to organize your recipes:

library
  |
  +-- cookbooks
  |
  +-- specs
        |
        +-- recipes
              |
              +-- <recipe_name>_spec.rb

Or force the example group into the spec:

describe 'cookbook::recipe', :type => :recipe do
  ...
end

Matchers

All of the standard RSpec matchers are available for you to use when testing Chef recipes.

Checking if a recipe contains a resource

Use the matcher contain_<resource_type> matcher:

  it { should contain_remote_file }

It can take the name of the resource as a parameter:

  it { should contain_remote_file('/etc/chef/dna.json') }

It can take the parameters that the resource takes:

  it { should contain_remote_file('/etc/chef/dna.json', {:action => :nothing}) }

Use the chained method with to test the further attributes that the resource gets:

  it { should contain_remote_file('/etc/chef/dna.json').with(:source, 'dna.json.erb') }

Use the chained method without to the the resource doesn't get further unexpected attributes:

  it { should contain_remote_file('/etc/chef/dna.json').without(:owner, :group) }

Settings

Cookbooks path

The path to the cookbooks can be specified using let for each group:

describe 'foo::bar' do
  let(:cookbook_path) { File.expand_path('../cookbooks', __FILE__) }
end

Or it can be set as a global RSpec setting:

RSpec.configure do |c|
  c.cookbook_path = File.expand_path('../cookbooks', __FILE__)
end

JSON attributes

Each recipe includes a node. This node can be feeded with a hash using let in the description group:

describe 'foo::bar' do
  let(:json_attributes) { {:foo => :bar} }
end

With a file in our file system:

describe 'foo::bar' do
  let(:json_attributes) { '/etc/chef/dna.json' }
end

Or with plain JSON:

describe 'foo::bar' do
  let(:json_attributes) { '{"foo": "bar"}' }
end

The JSON attributes can alson be set as a global RSpec setting:

RSpec.configure do |c|
  c.json_attributes = {:foo => :bar}
end

rspec-chef's People

Contributors

calavera avatar

Stargazers

 avatar

Watchers

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.