├── .drone.yml ├── .gitignore ├── .rubocop.yml ├── Dockerfile ├── Gemfile ├── Guardfile ├── README.md ├── bin └── meez ├── lib └── meez │ └── meez.rb ├── meez.gemspec └── templates ├── .drone.yml.erb ├── .kitchen.yml.erb ├── .rubocop.yml.erb ├── Dockerfile.erb ├── Guardfile.erb ├── Rakefile.erb ├── Vagrantfile.erb ├── chefspec ├── default_spec.rb.erb └── spec_helper.rb.erb └── serverspec ├── default_spec.rb.erb └── spec_helper.rb.erb /.drone.yml: -------------------------------------------------------------------------------- 1 | image: paulczar/meez 2 | env: 3 | - CI=drone 4 | - USE_SYSTEM_GECODE=1 5 | script: 6 | - bundle install 7 | - bundle exec berks install 8 | - bundle exec rake style spec 9 | notify: 10 | email: 11 | recipients: 12 | - paul.czarkowski@rackspace.com 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | .kitchen/ 4 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # Dear Rubocop, we're going to agree to disagree on the following: 2 | 3 | LineLength: 4 | Max: 200 5 | 6 | MethodLength: 7 | Max: 25 8 | 9 | ClassLength: 10 | Max: 200 11 | 12 | UnusedMethodArgument: 13 | Enabled: false -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM racker/precise-with-updates 2 | 3 | RUN apt-get -yqq update && apt-get -yqq install curl build-essential libxml2-dev libxslt-dev git autoconf wget python-pip 4 | 5 | RUN wget -q -O /tmp/chefdk.deb https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.1-1_amd64.deb \ 6 | && dpkg -i /tmp/chefdk.deb \ 7 | && rm /tmp/chefdk.deb 8 | 9 | RUN wget -q -O /tmp/vagrant.deb http://files.vagrantup.com/packages/a40522f5fabccb9ddabad03d836e120ff5d14093/vagrant_1.6.5_x86_64.deb \ 10 | && dpkg -i /tmp/vagrant.deb \ 11 | && rm /tmp/vagrant.deb 12 | 13 | RUN pip install swiftly awscli 14 | 15 | ENV PATH /opt/chefdk/bin:/opt/chefdk/embedded/bin:/root/.chefdk/gem/ruby/2.1.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 16 | ENV USE_SYSTEM_GECODE 1 17 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rake', '>= 10.3' 4 | gem 'rubocop', '= 0.23' 5 | gem 'guard', '>= 2.6' 6 | gem 'guard-rubocop', '>= 1.1' 7 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | guard :rubocop do 5 | watch(%r{.+\.rb$}) 6 | watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } 7 | end 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Meez 2 | ---- 3 | 4 | About 5 | ===== 6 | 7 | `Meez` is slang for `mise en place` 8 | 9 | `Mise en place` is a French phrase which means "putting in place", as in set up. It is used in professional kitchens to refer to organizing and arranging the ingredients (e.g., cuts of meat, relishes, sauces, par-cooked items, spices, freshly chopped vegetables, and other components) that a cook will require for the menu items that he or she expects to prepare during his/her shift.[1] The practice is also effective in home kitchens. 10 | 11 | `Meez` will create an opinionated chef cookbook skeleton complete with testing suite. 12 | 13 | Install 14 | ======= 15 | 16 | Setting the environment variable `USE_SYSTEM_GECODE=1` will help speed up builds by using the system `gecode` rather than compiling it from scratch. 17 | 18 | You may need to install `gecode` on your system: http://www.gecode.org/download.html 19 | 20 | for OSX I did 21 | 22 | ``` 23 | $ cd $( brew --prefix ) 24 | $ git checkout 3c5ca25 Library/Formula/gecode.rb 25 | $ brew install gecode 26 | $ brew link gecode 27 | ``` 28 | 29 | Official 30 | ---------- 31 | 32 | as of version `0.2.0` this is offered as a `chefdk` plugin. 33 | 34 | `chef gem install meez` 35 | 36 | 37 | Usage 38 | ===== 39 | 40 | ``` 41 | Usage: meez [options] 42 | 43 | Options 44 | -o, --cookbook-path USERNAME The directory where the cookbook will be created 45 | -C, --copyright COPYRIGHT_HOLDER The name of the copyright holder. 46 | -I, --license LICENSE The type of license under which a cookbook is distributed: apachev2, gplv2, gplv3, mit, or none (default). 47 | -m, --email EMAIL The email address for the individual who maintains the cookbook. 48 | -d, --kitchen-driver DRIVER The driver which use test-kitchen for creating platform instances: vagrant (default), docker 49 | -h, --help help 50 | ``` 51 | 52 | ### Example 53 | 54 | ``` 55 | $ meez --cookbook-path /tmp --copyright Foo -I apachev2 -m foo@bah.com test 56 | chef exec meez -o . test 57 | * Initializing Cookbook 58 | ** Creating cookbook test 59 | ** Creating README for cookbook: test 60 | ** Creating CHANGELOG for cookbook: test 61 | ** Creating metadata for cookbook: test 62 | Rewriting metadata.rb 63 | Rewriting recipes/default.rb 64 | * Initializing Berkshelf 65 | create test/Berksfile 66 | create test/Thorfile 67 | create test/chefignore 68 | create test/.gitignore 69 | create test/Gemfile 70 | * Initializing Vagrantfile 71 | Creating ./test/Vagrantfile from template 72 | * Initializing Knife 73 | adding chef gem to Gemfile 74 | * Initializing Rakefile 75 | Creating ./test/Rakefile from template 76 | adding rake gem to Gemfile 77 | * Initializing Rubocop 78 | Creating ./test/.rubocop.yml from template 79 | adding rubocop gem to Gemfile 80 | * Initializing Food Critic 81 | adding foodcritic gem to Gemfile 82 | * Initializing Chef Spec 83 | Creating ./test/test/unit/spec/spec_helper.rb from template 84 | Creating ./test/test/unit/spec/default_spec.rb from template 85 | adding chefspec gem to Gemfile 86 | * Initializing Server Spec 87 | Creating ./test/test/integration/default/serverspec/spec_helper.rb from template 88 | Creating ./test/test/integration/default/serverspec/default_spec.rb from template 89 | * Initializing Test Kitchen 90 | create .kitchen.yml 91 | append Rakefile 92 | append Thorfile 93 | exist test/integration/default 94 | append .gitignore 95 | append .gitignore 96 | append Gemfile 97 | append Gemfile 98 | You must run `bundle install' to fetch any new gems. 99 | Creating ./test/.kitchen.yml from template 100 | * Initializing Guard 101 | Creating ./test/Guardfile from template 102 | adding guard gem to Gemfile 103 | adding guard-rubocop gem to Gemfile 104 | adding guard-foodcritic gem to Gemfile 105 | * Initializing Drone 106 | Creating ./test/.drone.yml from template 107 | * Initializing Docker 108 | Creating ./test/Dockerfile from template 109 | Cookbook test created successfully 110 | Next steps... 111 | $ cd ./test 112 | $ export USE_SYSTEM_GECODE=1 113 | $ chef exec rake prepare 114 | $ chef exec rake test 115 | $ cd /tmp/test 116 | $ export USE_SYSTEM_GECODE=1 117 | $ chef exec rake prepare 118 | chef exec bundle install --path .bundle 119 | Fetching gem metadata from https://rubygems.org/....... 120 | Fetching additional metadata from https://rubygems.org/.. 121 | Resolving dependencies... 122 | Installing rake (10.3.2) 123 | ... 124 | ... 125 | Your bundle is complete! 126 | It was installed into ./.bundle 127 | chef exec berks install 128 | Resolving cookbook dependencies... 129 | Fetching 'test' from source at . 130 | Fetching cookbook index from https://supermarket.getchef.com... 131 | Using test (0.1.0) from source at . 132 | $ chef exec rake -T 133 | rake kitchen:all # Run all test instances 134 | rake kitchen:default-ubuntu-1204 # Run default-ubuntu-1204 test instance 135 | rake prepare # Install required Gems and Cookbooks 136 | rake prepare:chefdk # Install ChefDK 137 | rake style # Run all style checks 138 | rake unit # Run all unit tests 139 | ``` 140 | 141 | Contributing 142 | ------------ 143 | 144 | e.g. 145 | 146 | 1. Fork the repository on Github 147 | 2. Create a named feature branch (like `add_component_x`) 148 | 3. Write your change 149 | 4. Write tests for your change (if applicable) 150 | 5. Run the tests, ensuring they all pass 151 | 6. Submit a Pull Request using Github 152 | 153 | License and Authors 154 | ------------------- 155 | 156 | Authors: 157 | ======== 158 | 159 | Paul Czarkowski - paul.czarkowski@rackspace.com 160 | 161 | License: 162 | ======== 163 | 164 | Copyright 2014 Paul Czarkowski, Rackspace Inc. 165 | 166 | Licensed under the Apache License, Version 2.0 (the "License"); 167 | you may not use this file except in compliance with the License. 168 | You may obtain a copy of the License at 169 | 170 | http://www.apache.org/licenses/LICENSE-2.0 171 | 172 | Unless required by applicable law or agreed to in writing, software 173 | distributed under the License is distributed on an "AS IS" BASIS, 174 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 175 | See the License for the specific language governing permissions and 176 | limitations under the License. 177 | -------------------------------------------------------------------------------- /bin/meez: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Encoding: utf-8 3 | 4 | $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))) 5 | 6 | require 'optparse' 7 | require 'meez/meez' 8 | 9 | options = { 10 | path: './' 11 | } 12 | 13 | opt_parser = OptionParser.new do |opt| 14 | opt.banner = 'Usage: chef exec meez [options] ' 15 | opt.separator '' 16 | opt.separator 'Options' 17 | opt.on('-o', '--cookbook-path PATH', 'The directory where the cookbook will be created') do |path| 18 | options[:path] = path 19 | end 20 | opt.on('-C', '--copyright COPYRIGHT_HOLDER', 'The name of the copyright holder.') do |copyright| 21 | options[:copyright] = copyright 22 | end 23 | opt.on('-I', '--license LICENSE', 'The type of license under which a cookbook is distributed: apachev2, gplv2, gplv3, mit, or none (default).') do |license| 24 | options[:license] = license 25 | end 26 | opt.on('-m', '--email EMAIL', 'The email address for the individual who maintains the cookbook.') do |email| 27 | options[:email] = email 28 | end 29 | opt.on('-d', '--kitchen-driver DRIVER', 'The driver which use test-kitchen for creating platform instances: vagrant (default), docker') do |driver| 30 | options[:driver] = driver 31 | end 32 | opt.on('-h', '--help', 'help') do 33 | options[:help] = true 34 | puts opt_parser 35 | end 36 | opt.on('-v', '--version', 'version') do 37 | options[:version] = true 38 | puts 'meez version 0.2.7' 39 | end 40 | end 41 | 42 | opt_parser.parse! 43 | 44 | cookbook_name = ARGV.pop 45 | 46 | unless options[:help] || options[:version] 47 | if cookbook_name 48 | Meez.init(cookbook_name, options) 49 | puts "Cookbook #{cookbook_name} created successfully" 50 | puts 'Next steps...' 51 | puts " $ cd #{File.join(options[:path], cookbook_name)}" 52 | puts ' $ export USE_SYSTEM_GECODE=1' 53 | puts ' $ chef exec rake prepare' 54 | puts ' $ chef exec rake test' 55 | else 56 | puts 'Need to specify a cookbook' 57 | puts opt_parser 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /lib/meez/meez.rb: -------------------------------------------------------------------------------- 1 | # Encoding: utf-8 2 | # The main Meez driver 3 | class Meez 4 | require 'fileutils' 5 | 6 | def self.init(cookbook_name, options) 7 | init_cookbook(cookbook_name, options) 8 | init_berkshelf(cookbook_name, options) 9 | init_vagrant(cookbook_name, options) 10 | init_knife(cookbook_name, options) 11 | init_rakefile(cookbook_name, options) 12 | init_rubocop(cookbook_name, options) 13 | init_foodcritic(cookbook_name, options) 14 | init_chefspec(cookbook_name, options) 15 | init_serverspec(cookbook_name, options) 16 | init_kitchenci(cookbook_name, options) 17 | init_guard(cookbook_name, options) 18 | init_drone(cookbook_name, options) 19 | init_docker(cookbook_name, options) 20 | end 21 | 22 | def self.write_template(name, path, cookbook_name, options) 23 | require 'erb' 24 | template = File.join(File.dirname(__FILE__), '../../templates', name) 25 | target = File.join(path, File.basename(name, '.erb')) 26 | puts "\tCreating #{target} from template" 27 | content = ERB.new File.new(template).read 28 | File.open(target, 'w') { |f| f.write(content.result(binding)) } 29 | end 30 | 31 | def self.append_file(file, content) 32 | File.open(file, 'a') { |f| f.write("#{content}\n") } 33 | end 34 | 35 | def self.add_gem(cookbook_path, name, version = nil) 36 | puts "adding #{name} gem to Gemfile" 37 | if version 38 | append_file(File.join(cookbook_path, 'Gemfile'), "gem '#{name}', '#{version}'") 39 | else 40 | append_file(File.join(cookbook_path, 'Gemfile'), "gem '#{name}'") 41 | end 42 | end 43 | 44 | def self.gitignore(cookbook_path, file) 45 | append_file(File.join(cookbook_path, '.gitignore'), file) 46 | end 47 | 48 | def self.init_cookbook(cookbook_name, options) 49 | require 'chef/knife/cookbook_create' 50 | puts '* Initializing Cookbook' 51 | path = File.join(options[:path], cookbook_name) 52 | create_cookbook = Chef::Knife::CookbookCreate.new 53 | create_cookbook.name_args = [cookbook_name] 54 | create_cookbook.config[:cookbook_path] = options[:path] 55 | create_cookbook.config[:cookbook_copyright] = options[:copyright] || 'YOUR_COMPANY_NAME' 56 | create_cookbook.config[:cookbook_email] = options[:email] || 'YOUR_EMAIL' 57 | create_cookbook.config[:cookbook_license] = options[:license] || 'none' 58 | create_cookbook.run 59 | %w(metadata.rb recipes/default.rb).each do |file| 60 | puts "\tRewriting #{file}" 61 | contents = "# Encoding: utf-8\n#{File.read(File.join(path, file))}" 62 | File.open(File.join(path, file), 'w') { |f| f.write(contents) } 63 | end 64 | end 65 | 66 | def self.init_git(cookbook_name, options) 67 | puts '* Initializing GIT repo' 68 | path = File.join(options[:path], cookbook_name) 69 | require 'git' 70 | Git.init(path, repository: path) 71 | end 72 | 73 | def self.init_berkshelf(cookbook_name, options) 74 | puts '* Initializing Berkshelf' 75 | path = File.join(options[:path], cookbook_name) 76 | require 'berkshelf' 77 | require 'berkshelf/base_generator' 78 | require 'berkshelf/init_generator' 79 | Berkshelf::InitGenerator.new( 80 | [path], 81 | skip_test_kitchen: true, 82 | skip_vagrant: true 83 | ).invoke_all 84 | contents = File.read(File.join(path, 'Gemfile')) 85 | newgemfile = contents.gsub("\ngem 'berkshelf'\n", "\ngem 'berkshelf', '> 3.1'\n") 86 | File.open(File.join(path, 'Gemfile'), 'w') { |f| f.write(newgemfile) } 87 | end 88 | 89 | def self.init_kitchenci(cookbook_name, options) 90 | puts '* Initializing Test Kitchen' 91 | path = File.join(options[:path], cookbook_name) 92 | require 'kitchen' 93 | require 'kitchen/generator/init' 94 | Kitchen::Generator::Init.new([], {}, destination_root: path).invoke_all 95 | options[:driver] ||= 'vagrant' 96 | write_template('.kitchen.yml.erb', path, cookbook_name, options) 97 | add_gem(path, 'kitchen-docker') if options[:driver].eql? 'docker' 98 | end 99 | 100 | def self.init_vagrant(cookbook_name, options) 101 | puts '* Initializing Vagrantfile' 102 | path = File.join(options[:path], cookbook_name) 103 | write_template('Vagrantfile.erb', path, cookbook_name, options) 104 | end 105 | 106 | def self.init_chefspec(cookbook_name, options) 107 | puts '* Initializing Chef Spec' 108 | path = File.join(options[:path], cookbook_name) 109 | spec_path = File.join(path, 'test', 'unit', 'spec') 110 | FileUtils.mkdir_p(spec_path) 111 | write_template('chefspec/spec_helper.rb.erb', spec_path, cookbook_name, options) 112 | write_template('chefspec/default_spec.rb.erb', spec_path, cookbook_name, options) 113 | gitignore(path, '.coverage/*') 114 | add_gem(path, 'chefspec') 115 | end 116 | 117 | def self.init_rakefile(cookbook_name, options) 118 | puts '* Initializing Rakefile' 119 | path = File.join(options[:path], cookbook_name) 120 | write_template('Rakefile.erb', path, cookbook_name, options) 121 | add_gem(path, 'rake') 122 | end 123 | 124 | def self.init_rubocop(cookbook_name, options) 125 | puts '* Initializing Rubocop' 126 | path = File.join(options[:path], cookbook_name) 127 | write_template('.rubocop.yml.erb', path, cookbook_name, options) 128 | add_gem(path, 'rubocop') 129 | end 130 | 131 | def self.init_knife(cookbook_name, options) 132 | puts '* Initializing Knife' 133 | path = File.join(options[:path], cookbook_name) 134 | add_gem(path, 'chef', '> 11') 135 | end 136 | 137 | def self.init_foodcritic(cookbook_name, options) 138 | puts '* Initializing Food Critic' 139 | path = File.join(options[:path], cookbook_name) 140 | add_gem(path, 'foodcritic') 141 | end 142 | 143 | def self.init_serverspec(cookbook_name, options) 144 | puts '* Initializing Server Spec' 145 | path = File.join(options[:path], cookbook_name) 146 | spec_path = File.join(path, 'test', 'integration', 'default', 'serverspec') 147 | FileUtils.mkdir_p(spec_path) 148 | write_template('serverspec/spec_helper.rb.erb', spec_path, cookbook_name, options) 149 | write_template('serverspec/default_spec.rb.erb', spec_path, cookbook_name, options) 150 | end 151 | 152 | def self.init_guard(cookbook_name, options) 153 | puts '* Initializing Guard' 154 | path = File.join(options[:path], cookbook_name) 155 | write_template('Guardfile.erb', path, cookbook_name, options) 156 | add_gem(path, 'guard', '>= 2.6') 157 | add_gem(path, 'guard-rubocop', '>= 1.1') 158 | add_gem(path, 'guard-foodcritic', '>= 1.0.2') 159 | end 160 | 161 | def self.init_drone(cookbook_name, options) 162 | puts '* Initializing Drone' 163 | path = File.join(options[:path], cookbook_name) 164 | write_template('.drone.yml.erb', path, cookbook_name, options) 165 | end 166 | 167 | def self.init_docker(cookbook_name, options) 168 | puts '* Initializing Docker' 169 | path = File.join(options[:path], cookbook_name) 170 | write_template('Dockerfile.erb', path, cookbook_name, options) 171 | end 172 | 173 | def self.bundle_install(cookbook_name, options) 174 | require 'bundler' 175 | puts '* Running bundle install' 176 | path = File.join(options[:path], cookbook_name) 177 | puts "\t append .gitignore" 178 | Bundler.with_clean_env { exec({ 'BUNDLE_GEMFILE' => "#{path}/Gemfile" }, 'bundle install') } 179 | end 180 | end 181 | -------------------------------------------------------------------------------- /meez.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = %q(meez) 3 | s.version = '0.2.7' 4 | s.date = %q(2014-01-08) 5 | s.summary = 'Initializes a chef cookbook with TDD framework' 6 | s.description = < 11.12' 20 | s.add_dependency 'test-kitchen', '~> 1.2' 21 | s.add_dependency 'bundler', '~> 1.5' 22 | s.add_dependency 'berkshelf', '~> 3.1' 23 | end 24 | -------------------------------------------------------------------------------- /templates/.drone.yml.erb: -------------------------------------------------------------------------------- 1 | image: paulczar/meez 2 | env: 3 | - CI=drone 4 | - USE_SYSTEM_GECODE=1 5 | script: 6 | - rake prepare:chefdk 7 | - chef exec rake prepare 8 | - chef exec rake style unit 9 | -------------------------------------------------------------------------------- /templates/.kitchen.yml.erb: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | <% case options[:driver] when "vagrant" %>name: vagrant 4 | <% when "docker" %>name: docker 5 | provision_command: curl -L http://www.opscode.com/chef/install.sh | bash 6 | use_sudo: <%= `uname` == 'Darwin' ? false : true %> 7 | <% end %> 8 | provisioner: 9 | name: chef_solo 10 | 11 | platforms: 12 | - name: ubuntu-12.04 13 | 14 | suites: 15 | - name: default 16 | run_list: recipe[<%= cookbook_name %>::default] 17 | attributes: 18 | -------------------------------------------------------------------------------- /templates/.rubocop.yml.erb: -------------------------------------------------------------------------------- 1 | # Rubocop, we're buddies and all, but we're going to have to disagree on the following - 2 | 3 | WordArray: 4 | MinSize: 5 5 | -------------------------------------------------------------------------------- /templates/Dockerfile.erb: -------------------------------------------------------------------------------- 1 | # builds docker container to be used with CI 2 | 3 | FROM paulczar/meez 4 | 5 | ADD Gemfile /tmp/Gemfile 6 | 7 | ENV PATH /opt/chefdk/embedded/bin:/root/.chefdk/gem/ruby/2.1.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 8 | ENV USE_SYSTEM_GECODE 1 9 | 10 | RUN cd /tmp && bundle install -------------------------------------------------------------------------------- /templates/Guardfile.erb: -------------------------------------------------------------------------------- 1 | # Guardfile built by Meez ( http://github.com/paulczar/meez ) 2 | # for testing your chef cookbooks. 3 | 4 | guard :rubocop do 5 | watch(%r{.+\.rb$}) 6 | watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } 7 | end 8 | 9 | guard :foodcritic, cookbook_paths: '.', cli: ['--epic-fail', 'any'] do 10 | watch(%r{attributes/.+\.rb$}) 11 | watch(%r{providers/.+\.rb$}) 12 | watch(%r{recipes/.+\.rb$}) 13 | watch(%r{resources/.+\.rb$}) 14 | watch(%r{metadata\.rb$}) 15 | end -------------------------------------------------------------------------------- /templates/Rakefile.erb: -------------------------------------------------------------------------------- 1 | # Encoding: utf-8 2 | 3 | namespace :prepare do 4 | 5 | desc 'Install ChefDK' 6 | task :chefdk do 7 | begin 8 | gem 'chef-dk', '0.2.1' 9 | rescue Gem::LoadError 10 | puts 'ChefDK not found. Installing it for you...' 11 | sh %{wget -O /tmp/meez_chefdk.deb https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.1-1_amd64.deb} 12 | sh %{sudo dpkg -i /tmp/meez_chefdk.deb} 13 | end 14 | end 15 | 16 | task :bundle do 17 | if ENV['CI'] 18 | sh %{chef exec bundle install --path=.bundle --jobs 1 --retry 3 --verbose} 19 | else 20 | sh %{chef exec bundle install --path .bundle} 21 | end 22 | end 23 | 24 | task :berks do 25 | sh %{chef exec berks install} 26 | end 27 | 28 | end 29 | 30 | desc 'Install required Gems and Cookbooks' 31 | task prepare: ['prepare:bundle', 'prepare:berks'] 32 | 33 | namespace :style do 34 | task :rubocop do 35 | sh %{chef exec rubocop} 36 | end 37 | 38 | task :foodcritic do 39 | sh %{chef exec foodcritic .} 40 | end 41 | end 42 | 43 | desc 'Run all style checks' 44 | task style: ['style:foodcritic', 'style:rubocop'] 45 | 46 | namespace :integration do 47 | task :kitchen do 48 | sh %{chef exec kitchen test} 49 | end 50 | end 51 | 52 | task integration: ['integration:kitchen'] 53 | 54 | namespace :unit do 55 | task :chefspec do 56 | sh %{chef exec rspec test/unit/spec} 57 | end 58 | end 59 | 60 | desc 'Run all unit tests' 61 | task unit: ['unit:chefspec'] 62 | task spec: ['unit'] 63 | 64 | # Run all tests 65 | desc 'Run all tests' 66 | task test: ['style', 'unit', 'integration'] 67 | 68 | # The default rake task should just run it all 69 | desc 'Install required Gems and Cookbook then run all tests' 70 | task default: ['prepare', 'test' ] 71 | 72 | 73 | -------------------------------------------------------------------------------- /templates/Vagrantfile.erb: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure('2') do |config| 5 | config.vm.hostname = '<%= cookbook_name %>' 6 | config.vm.box = 'ubuntu-12.04' 7 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_#{config.vm.box}_chef-provisionerless.box" 8 | config.omnibus.chef_version = 'latest' 9 | config.berkshelf.enabled = true 10 | 11 | config.vm.provision :chef_solo do |chef| 12 | chef.json = { 13 | } 14 | 15 | chef.run_list = [ 16 | 'recipe[<%= cookbook_name %>::default]' 17 | ] 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /templates/chefspec/default_spec.rb.erb: -------------------------------------------------------------------------------- 1 | # Encoding: utf-8 2 | 3 | require_relative 'spec_helper' 4 | 5 | describe '<%= cookbook_name %>::default' do 6 | before { stub_resources } 7 | describe 'ubuntu' do 8 | let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } 9 | 10 | it 'writes some chefspec code' do 11 | skip 'todo' 12 | end 13 | 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /templates/chefspec/spec_helper.rb.erb: -------------------------------------------------------------------------------- 1 | # Encoding: utf-8 2 | require 'rspec/expectations' 3 | require 'chefspec' 4 | require 'chefspec/berkshelf' 5 | require 'chef/application' 6 | 7 | ::LOG_LEVEL = :fatal 8 | ::UBUNTU_OPTS = { 9 | platform: 'ubuntu', 10 | version: '12.04', 11 | log_level: ::LOG_LEVEL 12 | } 13 | ::CHEFSPEC_OPTS = { 14 | log_level: ::LOG_LEVEL 15 | } 16 | 17 | def stub_resources 18 | end 19 | 20 | at_exit { ChefSpec::Coverage.report! } 21 | -------------------------------------------------------------------------------- /templates/serverspec/default_spec.rb.erb: -------------------------------------------------------------------------------- 1 | # Encoding: utf-8 2 | 3 | require_relative 'spec_helper' 4 | 5 | describe 'default' do 6 | it { skip 'write some tests' } 7 | end 8 | -------------------------------------------------------------------------------- /templates/serverspec/spec_helper.rb.erb: -------------------------------------------------------------------------------- 1 | # Encoding: utf-8 2 | require 'serverspec' 3 | 4 | include Serverspec::Helper::Exec 5 | include Serverspec::Helper::DetectOS 6 | 7 | RSpec.configure do |c| 8 | c.before :all do 9 | c.path = '/sbin:/usr/bin' 10 | end 11 | end 12 | --------------------------------------------------------------------------------