2014-06-22 15:00:34 +02:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2014-06-05 10:50:37 +02:00
|
|
|
require 'rake'
|
|
|
|
require 'rspec/core/rake_task'
|
2014-06-16 16:20:21 +02:00
|
|
|
require 'rubocop/rake_task'
|
2014-06-05 10:50:37 +02:00
|
|
|
|
2014-06-16 16:20:21 +02:00
|
|
|
# Rubocop
|
|
|
|
desc 'Run Rubocop lint checks'
|
|
|
|
task :rubocop do
|
2014-06-22 12:57:10 +02:00
|
|
|
RuboCop::RakeTask.new
|
2014-06-16 16:20:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Lint the cookbook
|
2014-06-22 12:57:10 +02:00
|
|
|
desc 'Run linters'
|
|
|
|
task :run_all_linters => [:rubocop] # rubocop:disable Style/HashSyntax
|
2014-06-23 12:03:15 +02:00
|
|
|
task :default => :run_all_linters # rubocop:disable Style/HashSyntax
|
2014-06-16 16:20:21 +02:00
|
|
|
|
|
|
|
# Serverspec tests
|
2014-06-22 12:57:10 +02:00
|
|
|
suites = Dir.glob('*').select { |entry| File.directory?(entry) }
|
2014-06-05 10:50:37 +02:00
|
|
|
|
|
|
|
class ServerspecTask < RSpec::Core::RakeTask
|
|
|
|
attr_accessor :target
|
|
|
|
|
|
|
|
def spec_command
|
2014-06-22 12:57:10 +02:00
|
|
|
if target.nil?
|
|
|
|
puts 'specify either env TARGET_HOST or target_host='
|
2014-06-05 10:50:37 +02:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
cmd = super
|
|
|
|
"env TARGET_HOST=#{target} STANDALONE_SPEC=true #{cmd} --format documentation --no-profile"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :serverspec do
|
|
|
|
suites.each do |suite|
|
|
|
|
desc "Run serverspec suite #{suite}"
|
|
|
|
ServerspecTask.new(suite.to_sym) do |t|
|
2014-06-22 12:57:10 +02:00
|
|
|
t.rspec_opts = '--no-color --format html --out report.html' if ENV['format'] == 'html'
|
2015-01-14 13:37:40 +01:00
|
|
|
t.rspec_opts = '--no-color --format json --out report.json' if ENV['format'] == 'json'
|
2014-06-05 10:50:37 +02:00
|
|
|
t.target = ENV['TARGET_HOST'] || ENV['target_host']
|
|
|
|
t.ruby_opts = "-I #{suite}/serverspec"
|
|
|
|
t.pattern = "#{suite}/serverspec/*_spec.rb"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|