Project

fauxbag

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
ChefSpec plugin for stubbing data bags from JSON.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
>= 0
>= 0

Runtime

 Project Readme

Fauxbag

Adds load_databag_json support method to use with Data Bags and ChefSpec

Installation and Configuration

Add this line to your Gemfile:

  gem 'fauxbag'

And then execute:

  $ bundle

Include fauxbag in your spec_helper.rb file.

# mycookbook/spec/spec_helper.rb
require 'fauxbag'

Usage

The expected location for data bag items is a data_bags folder in the spec directory:

spec/data_bags/data_bag_name/data_bag_item.json

Methods

load_databag_item

The load_databag_item method requires the arguments of the data_bag_name folder and the data_bag_item without the .json:

load_databag_json(data_bag_name, data_bag_item)

load_chefzero_databag

The load_chefzero_databag method requires the data bag group (such as users) and returns all items as a single hash to be used with Chef-Zero:

load_chefzero_databag(data_bag_name)

Example

The expected layout of your cookbook and data bag fixtures:

mycookbook
.
├── README.md
├── attributes
├── metadata.rb
├── recipes
│   └── default.rb
└── spec
    ├── data_bags
    │   └── users
    │       └── hansolo.json
    └── default_spec.rb

Using the data_bag fixtures:

# mycookbook/spec/default_spec.rb
require 'spec_helper'

describe 'mycookbook::default' do
  it "installs something for all users" do
    # Loads JSON from mycookbook/spec/data_bags/users/hansolo.json
    fauxbag = load_databag_json('users', 'hansolo')
    stub_data_bag_item('users', 'hansolo').and_return(fauxbag)

    # ... rest of the spec test with expectation
  end
end

Contributing

  1. Fork it ( http://github.com/sqm/fauxbag/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request