summaryrefslogtreecommitdiff
path: root/tasks
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-09-29 22:03:48 -0700
committerJohn Keiser <john@johnkeiser.com>2015-09-30 12:55:02 -0700
commite6959f4e9306a65ac52bc9087acdf4a0bccc2f59 (patch)
tree1da4ef4cf6f742d8d62587d20ff01639278a0659 /tasks
parentd1a0e4b9dc4b5f00ce7fa5d56866fa0cbe8413e9 (diff)
downloadchef-e6959f4e9306a65ac52bc9087acdf4a0bccc2f59.tar.gz
Add external tests for chefspec, chef-sugar, chef-rewind, foodcritic and poise
Diffstat (limited to 'tasks')
-rw-r--r--tasks/external_tests.rb64
1 files changed, 41 insertions, 23 deletions
diff --git a/tasks/external_tests.rb b/tasks/external_tests.rb
index 2ff991ddf7..b87b5bf1d6 100644
--- a/tasks/external_tests.rb
+++ b/tasks/external_tests.rb
@@ -1,29 +1,47 @@
-task :chef_sugar_spec do
- gem_path = Bundler.environment.specs['chef-sugar'].first.full_gem_path
- system("cd #{gem_path} && rake")
-end
+require 'tempfile'
-task :foodcritic_spec do
- gem_path = Bundler.environment.specs['foodcritic'].first.full_gem_path
- system("cd #{gem_path} && rake test")
+def bundle_exec_with_chef(test_gem, command)
+ gem_path = Bundler.environment.specs[test_gem].first.full_gem_path
+ gemfile_path = File.join(gem_path, 'Gemfile.chef-external-test')
+ gemfile = File.open(gemfile_path, "w")
+ begin
+ IO.read(File.join(gem_path, 'Gemfile')).each_line do |line|
+ if line =~ /^\s*gemspec/
+ next
+ elsif line =~ /^\s*gem 'chef'|\s*gem "chef"/
+ next
+ elsif line =~ /^\s*dev_gem\s*['"](.+)['"]\s*$/
+ line = "gem '#{$1}', github: 'poise/#{$1}'"
+ elsif line =~ /\s*gem\s*['"]#{test_gem}['"]/ # foodcritic
+ next
+ end
+ gemfile.puts(line)
+ end
+ gemfile.puts("gem 'chef', path: #{File.expand_path('../..', __FILE__).inspect}")
+ gemfile.puts("gemspec path: #{gem_path.inspect}")
+ gemfile.close
+ Dir.chdir(gem_path) do
+ system({ 'BUNDLE_GEMFILE' => gemfile.path, 'RUBYOPT' => nil }, "bundle install")
+ system({ 'BUNDLE_GEMFILE' => gemfile.path, 'RUBYOPT' => nil }, "bundle exec #{command}")
+ end
+ ensure
+ File.delete(gemfile_path)
+ end
end
-task :chefspec_spec do
- gem_path = Bundler.environment.specs['chefspec'].first.full_gem_path
- system("cd #{gem_path} && rake")
-end
+EXTERNAL_PROJECTS = {
+ "chef-sugar" => "rake",
+ "foodcritic" => "rake test",
+ "chefspec" => "rake",
+ "chef-rewind" => "rake spec",
+ "poise" => "rake spec",
+ "halite" => "rake spec"
+}
-task :chef_rewind_spec do
- gem_path = Bundler.environment.specs['chef-rewind'].first.full_gem_path
- system("cd #{gem_path} && rake spec")
-end
-
-task :poise_spec do
- gem_path = Bundler.environment.specs['poise'].first.full_gem_path
- system("cd #{gem_path} && rake spec")
-end
+task :external_specs => EXTERNAL_PROJECTS.keys.map { |g| :"#{g.sub("-","_")}_spec" }
-task :halite_spec do
- gem_path = Bundler.environment.specs['halite'].first.full_gem_path
- system("cd #{gem_path} && rake spec")
+EXTERNAL_PROJECTS.each do |test_gem, command|
+ task :"#{test_gem.gsub('-','_')}_spec" do
+ bundle_exec_with_chef(test_gem, command)
+ end
end