Skip to content

Instantly share code, notes, and snippets.

@parnurzeal
Last active August 29, 2015 13:58
Show Gist options
  • Save parnurzeal/10228276 to your computer and use it in GitHub Desktop.
Save parnurzeal/10228276 to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
group :test do
gem 'chefspec', '~> 3.4.0'
gem 'foodcritic', '~> 3.0.3'
gem 'strainer', '~> 3.0'
gem 'test-kitchen', '~> 1.2.1'
gem 'knife-spork', '~> 1.3.2'
gem 'hipchat', '~> 1.1.0'
gem 'guard', '~> 1.8.3'
gem 'guard-foodcritic', '~> 1.0.2'
gem 'guard-rspec', '~> 3.1.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