Last active
August 29, 2015 14:11
-
-
Save charlesjohnson/ba0a8f63ee0b59c72133 to your computer and use it in GitHub Desktop.
Example Chefspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: Cookbook | |
# Spec:: default | |
# | |
require 'spec_helper' | |
describe 'cookbook::default' do | |
shared_examples_for :the_default_behavior do | |
it 'converges successfully' do | |
chef_run # This should not raise an error | |
end | |
end | |
context 'When all attributes are default, on an unspecified platform' do | |
let(:chef_run) do | |
runner = ChefSpec::ServerRunner.new | |
runner.converge(described_recipe) | |
end | |
it 'sets the default attributes correctly' do | |
expect(chef_run.node['cookbook']['feature1']).to eq(false) | |
end | |
it_behaves_like :the_default_behavior | |
end | |
context 'When all attributes are default, on RHEL-family platforms' do | |
let(:chef_run) do | |
runner = ChefSpec::ServerRunner.new(RHEL_OPTS) | |
runner.converge(described_recipe) | |
end | |
it_behaves_like :the_default_behavior | |
end | |
context 'When the feature1 attribute is true, on RHEL-family platforms' do | |
let(:chef_run) do | |
runner = ChefSpec::ServerRunner.new(RHEL_OPTS) | |
runner.node.set['cookbook']['feature1'] = true | |
runner.converge(described_recipe) | |
end | |
it_behaves_like :the_default_behavior | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment