Skip to content

Instantly share code, notes, and snippets.

@jjasghar
Forked from charlesjohnson/default_spec.rb
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjasghar/3aa254d70c7f1d07d414 to your computer and use it in GitHub Desktop.
Save jjasghar/3aa254d70c7f1d07d414 to your computer and use it in GitHub Desktop.
#
# Cookbook Name:: Cookbook
# Spec:: default
#
require 'spec_helper'
describe 'cookbook::default' do
shared_examples_for :default_recipe 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 :default_recipe
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 :default_recipe
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 :default_recipe
end
end
@jjasghar
Copy link
Author

let(:chef_run) { ChefSpec::Runner.new.converge('ntp::default') }
let(:ntp) { chef_run.node['ntp'] }
it 'sets the default attributes correctly' do
expect(ntp['servers']).to match_array(%w(0.pool.ntp.org
1.pool.ntp.org
2.pool.ntp.org
3.pool.ntp.org))
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment