Skip to content

Instantly share code, notes, and snippets.

@charlesjohnson
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save charlesjohnson/ba0a8f63ee0b59c72133 to your computer and use it in GitHub Desktop.
Save charlesjohnson/ba0a8f63ee0b59c72133 to your computer and use it in GitHub Desktop.
Example Chefspec
#
# 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