Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Last active December 15, 2015 16:38
Show Gist options
  • Save jtimberman/5290033 to your computer and use it in GitHub Desktop.
Save jtimberman/5290033 to your computer and use it in GitHub Desktop.
This Thor task should get you all set up to run test kitchen 1.0.0.alpha.2 with vagrant 1.1.
#
# Author:: Joshua Timberman <joshua@opscode.com>
#
# Copyright (c) 2013, Opscode, Inc. <legal@opscode.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
begin
require 'kitchen/thor_tasks'
Kitchen::ThorTasks.new
rescue LoadError
puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
end
class Cookbook < Thor
include Thor::Actions
desc 'prep', 'prepare the Test Kitchen'
def prep
unless File.exists?('./.kitchen/prepared')
run 'vagrant plugin install berkshelf-vagrant'
run 'gem install berkshelf'
run 'gem install kitchen-vagrant -v 0.7.4'
run 'gem install test-kitchen --pre'
empty_directory './.kitchen'
create_file './.kitchen/prepared'
else
puts "This kitchen is already prepared"
end
end
require 'mixlib/shellout'
desc 'foodcritic', 'run foodcritic'
def foodcritic
f = Mixlib::ShellOut.new('foodcritic -f ~FC007 .')
f.run_command
raise "Foodcritic failed" if f.exitstatus > 0
end
desc 'syntax', 'check syntax'
def syntax
s = Mixlib::ShellOut.new("knife cookbook test -o .. #{File.basename(Dir.pwd)}")
s.run_command
raise "Syntax check failed" if s.exitstatus > 0
end
desc 'test', 'Run all the tests'
def test
syntax
foodcritic
invoke 'kitchen:all'
end
end
@svanzoest
Copy link

it would be good to add tailor to this too.
We have been adding..

class Tailor < Thor
  require 'tailor/cli'

  desc "lint", "check style"
  def lint
     ::Tailor::Logger.log = false
     tailor = ::Tailor::CLI.new []
     tailor.execute!
  end
end

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