On Github paulczar / TDD-with-chef-and-strainer
Created by Paul Czarkowski / @pczarkowski
tailor parses Ruby files and measures them with against a number of common style conventions.
A linting tool for chef cookbooks, tests for common chef style patterns and other issues that might break converge.
# Strainerfile tailor: bundle exec tailor knife test: bundle exec knife cookbook test $COOKBOOK foodcritic: bundle exec foodcritic -f any $SANDBOX/$COOKBOOK chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec
cookbook/Strainerfile
A skeleton chef cookbook with all the wiring for testing
We're going to deploy this rails app https://github.com/paulczar/ircaas
metadata.rb
name 'ircaas' maintainer 'Paul Czarkowski' maintainer_email 'username.taken@gmail.com' license 'All rights reserved' description 'Installs/Configures ircaas' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '0.1.0' recipe "ircaas::default", "does nothing" recipe "ircaas::database", "set up database" recipe "ircaas::application", "set up rails environment, install code" %w{ ubuntu }.each do |os| supports os end %w{ ruby git }.each do |dep| depends dep end
README.md
Requirements ============== Chef 0.11.0 or higher required (for Chef environment use). Cookbooks ---------------- The following cookbooks are dependencies: * apt * ruby * git Recipes ======= ircaas::application --------------------------- * creates user `ircaas` * includes recipes `git::default`, `ruby::default` * Install IRCaaS Application code from `https://github.com/paulczar/ircaas` Attributes ========== ircaas['user'] - user to run application as ircaas['git']['repo'] - repo containing IRCaaS code ircaas['git']['branch'] - Branch to download
spec/application_spec.rb
require_relative 'spec_helper' describe 'ircaas::application' do describe 'ubuntu' do before do @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |node| node.set['ircaas'] = { user: 'ircaas', path: '/opt/ircaas', git: { repo: 'ssh://git.path', branch: 'master' } } end @chef_run.converge 'ircaas::application' end it 'creates ircaas user' do expect(@chef_run).to create_user('ircaas') end it 'includes ruby::default recipe' do expect(@chef_run).to include_recipe 'ruby::default' end it 'includes git::default recipe' do expect(@chef_run).to include_recipe 'git::default' end it 'checkouts ircaas from repo' do expect(@chef_run).to checkout_git("clone /opt/ircaas").with(repository: 'ssh://git.path', branch: 'master') end end end
recipe/application.rb
# Cookbook Name:: ircaas # Recipe:: application user node['ircaas']['user'] do username node['ircaas']['user'] comment "ircaas User" shell "/bin/bash" home "/home/ircaas" system true end include_recipe 'ruby::default' include_recipe 'git::default' git "clone #{node['ircaas']['path']}" do repository node['ircaas']['git']['repo'] branch node['ircaas']['git']['branch'] destination node['ircaas']['path'] action :checkout end