forked from inviqa/chef-php-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
executable file
·51 lines (40 loc) · 1.18 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env rake
# Don't output shell commands for fileutils
Rake::FileUtilsExt.verbose(false)
# Helpers
def sandbox_path
File.join(File.dirname(__FILE__), %W(tmp cookbooks #{cookbook_name}))
end
def cookbook_name
File.basename(File.dirname(__FILE__))
end
# test task
desc 'Run the default tests'
task :test => ['prepare_sandbox', 'knife', 'foodcritic']
# default task (test)
task :default => :test
# knife test
desc 'Runs knife cookbook test'
task :knife do
Rake::Task[:prepare_sandbox].invoke
sh "bundle exec knife cookbook test #{cookbook_name} -o #{sandbox_path}/../"
end
# foodcritic
desc 'Runs foodcritic linter'
task :foodcritic do
Rake::Task[:prepare_sandbox].invoke
if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup)
if sh "foodcritic -C -f any #{sandbox_path}"
puts 'foodcritic tests passed!'
end
else
puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2."
end
end
# sandbox helper
task :prepare_sandbox do
files = %w{*.md *.rb attributes definitions files providers recipes resources spec templates test}
rm_rf sandbox_path
mkdir_p sandbox_path
cp_r Dir.glob("{#{files.join(',')}}"), sandbox_path
end