Skip to content

Instantly share code, notes, and snippets.

@obazoud
Created February 26, 2014 21:13
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 obazoud/9238693 to your computer and use it in GitHub Desktop.
Save obazoud/9238693 to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
group :test do
gem 'chefspec', '~> 1.3'
gem 'foodcritic', '~> 2.1'
gem 'strainer', '~> 3.0'
gem 'test-kitchen', '~> 1.0.0.alpha'
gem 'kitchen-lxc', '~> 0.0.1.beta1'
gem 'knife-spork', '~> 1.0.17'
gem 'hipchat', '~> 0.10.0'
gem 'guard', '~> 1.8'
gem 'guard-foodcritic', '~> 1.0'
gem 'guard-rspec', '~> 3.0'
end
require 'spec_helper'
# Replace USERNAME with your username!
describe 'USERNAME-myface::default' do
let(:chef_run) do
run = ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04')
run.converge('USERNAME-myface::default')
end
it 'installs apache2' do
expect(chef_run).to install_package('apache2')
end
it 'starts the apache2 service' do
expect(chef_run).to start_service('apache2')
end
it 'sets apache2 to start on boot' do
expect(chef_run).to set_service_to_start_on_boot 'apache2'
end
end
require 'chefspec'
guard :rspec, cli: '--color', all_on_start: false do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{recipes/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end
guard :foodcritic, cookbook_paths: '.', all_on_start: false do
watch(%r{attributes/.+\.rb$})
watch(%r{providers/.+\.rb$})
watch(%r{recipes/.+\.rb$})
watch(%r{resources/.+\.rb$})
end
knife: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic $SANDBOX/$COOKBOOK -f any
rspec: (cd $COOKBOOK && bundle exec rspec --color --format documentation)
package 'apache2'
service 'apache2' do
action [:enable, :start]
end
bundle install --path /var/lib/jenkins/support/vendor
bundle exec strainer test
require 'spec_helper'
# Replace USERNAME with your username!
describe 'USERNAME-myface::default' do
let(:chef_run) do
run = ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04')
run.converge('USERNAME-myface::default')
end
it 'installs apache2' do
expect(chef_run).to install_package('apache2')
end
it 'starts the apache2 service' do
expect(chef_run).to start_service('apache2')
end
it 'sets apache2 to start on boot' do
expect(chef_run).to set_service_to_start_on_boot 'apache2'
end
it 'creates the default template' do
expect(chef_run).to create_file('/var/www/index.html')
end
it 'creates the site with the correct content' do
template = chef_run.template('/var/www/index.html')
expect(template.owner).to eq('root')
expect(template.group).to eq('root')
end
end
package 'apache2'
service 'apache2' do
action [:enable, :start]
end
template '/var/www/index.html' do
owner 'root'
group 'root'
mode '0755'
source 'index.html.erb'
end
<html>
<head>
<title>Welcome to <%= node['fqdn'] %></title>
</head>
<body>
<p>Here's everything you need to know about <%= node['fqdn'] %>:</p>
<pre><%= JSON.pretty_generate(node.to_hash) %></pre>
</body>
</html>
---
driver_plugin: lxc
driver_config:
use_sudo: true
platforms:
- name: ubuntu-12.04
driver_config:
base_container: ubuntu_12.04
username: ubuntu
password: ubuntu
suites:
- name: default
run_list: ["recipe[myface]"]
attributes: {}
knife: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic $SANDBOX/$COOKBOOK -f any
rspec: (cd $COOKBOOK && bundle exec rspec --color --format documentation)
kitchen: (cd $COOKBOOK && bundle exec kitchen test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment