Adds load_databag_json
support method to use with Data Bags and ChefSpec
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'
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
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)
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)
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
- Fork it ( http://github.com/sqm/fauxbag/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request