EcomDev::ChefSpec
A set of valuable helper to make writing ChefSpecs even more easier.
Features:
-
You can define matchers for your LWRP and HWRP by using DSL based file in your specs directory.
-
By default it looks in
spec/matchers.rb
,spec/matchers/*.rb
,spec/library/matchers.rb
,spec/library/matchers/*.rb
-
Example of the file DSL
matcher :resource_name, :action matcher :resource_name, [:delete, :create] runner :resource_name
-
It automatically includes matchers from other recipes, that contain such a Ruby file
-
-
By default it mocks any inclusion of recipes, except described one. You can specify additional one by calling
allow_recipe
in spec DSL. -
Allows to supply additional cookbook directory for your specs. Just add in
spec_helper.rb
file the following codeEcomDev::ChefSpec::Configuration.cookbook_path('path/to/your/test/cookbooks') EcomDev::ChefSpec::Configuration.cookbook_path('another/path/to/your/test/cookbooks')
It will automatically include the following paths for cookbook search:
- Berkshelf or Librarian path if any of those was included before
path/to/your/test/cookbooks
another/path/to/your/test/cookbooks
-
Allows to create platform based test cases by calling
platform(*filters)
method. Platform file is a json of such a structure:{ "os": { "ubuntu": ["10.04", "12.04", "13.10", "14.04"], "debian": ["6.0.5", "7.2", "7.4"], "freebsd": "9.2", "centos": ["5.8","6.4", "6.5"], "redhat": ["5.6", "6.3", "6.4"], "fedora": ["18", "19", "20"] }, "family": { "debian": ["ubuntu", "debian"], "rhel": ["redhat", "centos"], "fedora": ["fedora"], "freebsd": ["freebsd"] } }
By default this file is read from such location spec/platform.json. You can override it by specifying
EcomDev::ChefSpec::Helpers::Platform.platform_path='path/to/dir'
andEcomDev::ChefSpec::Helpers::Platform.platform_file='file.json'
or directly by callingplatform_load(file, path)
in your test case bodyWhen calling
platform
method you can pass a ruby block, so it will iterate over specified platforms:platform(:debian, :ubuntu) do |os, version| context 'In scope of ' + os + ' ' + version do it 'does crazy thing' do # .. you test code end end end
it will produce the following output:
In scope of ubuntu 14.04 does crazy things In scope of debian 7.4 does crazy things
Build Status
Installation
Add this line to your application's Gemfile:
gem 'ecomdev-chefspec'
And then execute:
bundle
Or install it yourself as:
gem install ecomdev-chefspec
Usage
Inside of your specs helper you should include this library after chefspec
require 'ecomdev/chefspec'
Please note, that you should include it in the end, after all the chef spec files are included. E.g. if you use bershelf loader for your cookbooks, you should include ecomdev/chefspec
after you've included chefspec/berkshelf
Contributing
- Fork it ( https://github.com/EcomDev/ecomdev-chefspec/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