From 39ff4b937123ae053b2ba61353437ccaf0fcc8ca Mon Sep 17 00:00:00 2001 From: Daniel DeLeo Date: Sun, 9 May 2010 09:56:21 -0700 Subject: allow other rake tasks to run when rspec/cucumber not installed --- Rakefile | 301 ++++++++++++++++++++++++++-------------------------- chef-solr/Rakefile | 61 +++++++---- chef/Rakefile | 19 ++++ chef/tasks/rspec.rb | 88 +++++++++------ 4 files changed, 270 insertions(+), 199 deletions(-) diff --git a/Rakefile b/Rakefile index aa7c8f7e9a..0376fbf5ce 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,6 @@ # -# Rakefile for Chef -# # Author:: Adam Jacob () +# Author:: Daniel DeLeo () # Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # @@ -20,7 +19,6 @@ gems = %w[chef chef-server-api chef-server-webui chef-solr] require 'rubygems' -require 'cucumber/rake/task' desc "Build the chef gems" task :gem do @@ -213,14 +211,14 @@ def wait_for_ctrlc end end -desc "Run a Devel instance of Chef" +desc "Run a development instance of Chef" task :dev do start_dev_environment wait_for_ctrlc end namespace :dev do - desc "Install a test instance of Chef for doing features against" + desc "Run a test instance of Chef suitable for cucumber tests" task :features do start_dev_environment("features") wait_for_ctrlc @@ -309,100 +307,122 @@ namespace :dev do end end -Cucumber::Rake::Task.new(:features) do |t| - t.profile = "default" -end +begin + require 'cucumber/rake/task' -namespace :features do - desc "Run cucumber tests for the REST API" - Cucumber::Rake::Task.new(:api) do |t| - t.profile = "api" + Cucumber::Rake::Task.new(:features) do |t| + t.profile = "default" end - namespace :api do - [ :nodes, :roles, :clients ].each do |api| - Cucumber::Rake::Task.new(api) do |apitask| - apitask.profile = "api_#{api.to_s}" - end - namespace api do - %w{create delete list show update}.each do |action| - Cucumber::Rake::Task.new("#{action}") do |t| - t.profile = "api_#{api.to_s}_#{action}" + namespace :features do + desc "Run cucumber tests for the REST API" + Cucumber::Rake::Task.new(:api) do |t| + t.profile = "api" + end + + namespace :api do + [ :nodes, :roles, :clients ].each do |api| + Cucumber::Rake::Task.new(api) do |apitask| + apitask.profile = "api_#{api.to_s}" + end + namespace api do + %w{create delete list show update}.each do |action| + Cucumber::Rake::Task.new("#{action}") do |t| + t.profile = "api_#{api.to_s}_#{action}" + end end end end - end - namespace :nodes do - Cucumber::Rake::Task.new("sync") do |t| - t.profile = "api_nodes_sync" + namespace :nodes do + Cucumber::Rake::Task.new("sync") do |t| + t.profile = "api_nodes_sync" + end end - end - namespace :cookbooks do - desc "Run cucumber tests for the cookbooks portion of the REST API" - Cucumber::Rake::Task.new(:cookbooks) do |t| - t.profile = "api_cookbooks" - end + namespace :cookbooks do + desc "Run cucumber tests for the cookbooks portion of the REST API" + Cucumber::Rake::Task.new(:cookbooks) do |t| + t.profile = "api_cookbooks" + end - Cucumber::Rake::Task.new(:cookbook_tarballs) do |t| - t.profile = "api_cookbooks_tarballs" + Cucumber::Rake::Task.new(:cookbook_tarballs) do |t| + t.profile = "api_cookbooks_tarballs" + end end - end - namespace :data do - desc "Run cucumber tests for the data portion of the REST API" - Cucumber::Rake::Task.new(:data) do |t| - t.profile = "api_data" - end + namespace :data do + desc "Run cucumber tests for the data portion of the REST API" + Cucumber::Rake::Task.new(:data) do |t| + t.profile = "api_data" + end - desc "Run cucumber tests for deleting data via the REST API" - Cucumber::Rake::Task.new(:delete) do |t| - t.profile = "api_data_delete" + desc "Run cucumber tests for deleting data via the REST API" + Cucumber::Rake::Task.new(:delete) do |t| + t.profile = "api_data_delete" + end + desc "Run cucumber tests for adding items via the REST API" + Cucumber::Rake::Task.new(:item) do |t| + t.profile = "api_data_item" + end end - desc "Run cucumber tests for adding items via the REST API" - Cucumber::Rake::Task.new(:item) do |t| - t.profile = "api_data_item" + + namespace :search do + desc "Run cucumber tests for searching via the REST API" + Cucumber::Rake::Task.new(:search) do |t| + t.profile = "api_search" + end + + desc "Run cucumber tests for listing search endpoints via the REST API" + Cucumber::Rake::Task.new(:list) do |t| + t.profile = "api_search_list" + end + desc "Run cucumber tests for searching via the REST API" + Cucumber::Rake::Task.new(:show) do |t| + t.profile = "api_search_show" + end + desc "Run cucumber tests for searching via the REST API" + Cucumber::Rake::Task.new(:reindex) do |t| + t.profile = "api_search_reindex" + end end end - namespace :search do - desc "Run cucumber tests for searching via the REST API" - Cucumber::Rake::Task.new(:search) do |t| - t.profile = "api_search" - end + desc "Run cucumber tests for the chef client" + Cucumber::Rake::Task.new(:client) do |t| + t.profile = "client" + end - desc "Run cucumber tests for listing search endpoints via the REST API" - Cucumber::Rake::Task.new(:list) do |t| - t.profile = "api_search_list" + namespace :client do + Cucumber::Rake::Task.new(:roles) do |t| + t.profile = "client_roles" end - desc "Run cucumber tests for searching via the REST API" - Cucumber::Rake::Task.new(:show) do |t| - t.profile = "api_search_show" + + Cucumber::Rake::Task.new(:run_interval) do |t| + t.profile = "client_run_interval" end - desc "Run cucumber tests for searching via the REST API" - Cucumber::Rake::Task.new(:reindex) do |t| - t.profile = "api_search_reindex" + + Cucumber::Rake::Task.new(:cookbook_sync) do |t| + t.profile = "client_cookbook_sync" end end - end - - desc "Run cucumber tests for the chef client" - Cucumber::Rake::Task.new(:client) do |t| - t.profile = "client" - end - namespace :client do - Cucumber::Rake::Task.new(:roles) do |t| - t.profile = "client_roles" + desc "Run cucumber tests for the cookbooks" + Cucumber::Rake::Task.new(:cookbooks) do |t| + t.profile = "cookbooks" end - Cucumber::Rake::Task.new(:run_interval) do |t| - t.profile = "client_run_interval" + namespace :cookbook do + + desc "Run cucumber tests for the cookbook metadata" + Cucumber::Rake::Task.new(:metadata) do |t| + t.profile = "cookbook_metadata" + end end - Cucumber::Rake::Task.new(:cookbook_sync) do |t| - t.profile = "client_cookbook_sync" + desc "Run cucumber tests for the recipe language" + Cucumber::Rake::Task.new(:language) do |t| + t.profile = "language" end Cucumber::Rake::Task.new(:attribute_settings) do |t| @@ -410,100 +430,85 @@ namespace :features do end end - desc "Run cucumber tests for the cookbooks" - Cucumber::Rake::Task.new(:cookbooks) do |t| - t.profile = "cookbooks" - end - - namespace :cookbook do - - desc "Run cucumber tests for the cookbook metadata" - Cucumber::Rake::Task.new(:metadata) do |t| - t.profile = "cookbook_metadata" + desc "Run cucumber tests for searching in recipes" + Cucumber::Rake::Task.new(:search) do |t| + t.profile = "search" end - end - desc "Run cucumber tests for the recipe language" - Cucumber::Rake::Task.new(:language) do |t| - t.profile = "language" - end - - desc "Run cucumber tests for searching in recipes" - Cucumber::Rake::Task.new(:search) do |t| - t.profile = "search" - end - - Cucumber::Rake::Task.new(:language) do |t| - t.profile = "language" - end - - namespace :language do - Cucumber::Rake::Task.new(:recipe_include) do |t| - t.profile = "recipe_inclusion" - end - Cucumber::Rake::Task.new(:attribute_include) do |t| - t.profile = "attribute_inclusion" + Cucumber::Rake::Task.new(:language) do |t| + t.profile = "language" end - end - - Cucumber::Rake::Task.new(:lwrp) do |t| - t.profile = "lwrp" - end - - desc "Run cucumber tests for providers" - Cucumber::Rake::Task.new(:provider) do |t| - t.profile = "provider" - end - - namespace :provider do - desc "Run cucumber tests for deploy resources" - Cucumber::Rake::Task.new(:deploy) do |t| - t.profile = "provider_deploy" + namespace :language do + Cucumber::Rake::Task.new(:recipe_include) do |t| + t.profile = "recipe_inclusion" + end + Cucumber::Rake::Task.new(:attribute_include) do |t| + t.profile = "attribute_inclusion" + end end - desc "Run cucumber tests for directory resources" - Cucumber::Rake::Task.new(:directory) do |t| - t.profile = "provider_directory" + Cucumber::Rake::Task.new(:lwrp) do |t| + t.profile = "lwrp" end - desc "Run cucumber tests for execute resources" - Cucumber::Rake::Task.new(:execute) do |t| - t.profile = "provider_execute" + desc "Run cucumber tests for providers" + Cucumber::Rake::Task.new(:provider) do |t| + t.profile = "provider" end - desc "Run cucumber tests for file resources" - Cucumber::Rake::Task.new(:file) do |t| - t.profile = "provider_file" - end - desc "Run cucumber tests for remote_file resources" - Cucumber::Rake::Task.new(:remote_file) do |t| - t.profile = "provider_remote_file" - end + namespace :provider do + desc "Run cucumber tests for deploy resources" + Cucumber::Rake::Task.new(:deploy) do |t| + t.profile = "provider_deploy" + end - desc "Run cucumber tests for template resources" - Cucumber::Rake::Task.new(:template) do |t| - t.profile = "provider_template" - end + desc "Run cucumber tests for directory resources" + Cucumber::Rake::Task.new(:directory) do |t| + t.profile = "provider_directory" + end - Cucumber::Rake::Task.new(:remote_directory) do |t| - t.profile = "provider_remote_directory" - end + desc "Run cucumber tests for execute resources" + Cucumber::Rake::Task.new(:execute) do |t| + t.profile = "provider_execute" + end - Cucumber::Rake::Task.new(:git) do |t| - t.profile = "provider_git" - end + desc "Run cucumber tests for file resources" + Cucumber::Rake::Task.new(:file) do |t| + t.profile = "provider_file" + end - namespace :package do - desc "Run cucumber tests for macports packages" - Cucumber::Rake::Task.new(:macports) do |t| - t.profile = "provider_package_macports" + desc "Run cucumber tests for remote_file resources" + Cucumber::Rake::Task.new(:remote_file) do |t| + t.profile = "provider_remote_file" end - Cucumber::Rake::Task.new(:gems) do |g| - g.profile = "provider_package_rubygems" + desc "Run cucumber tests for template resources" + Cucumber::Rake::Task.new(:template) do |t| + t.profile = "provider_template" + end + + Cucumber::Rake::Task.new(:remote_directory) do |t| + t.profile = "provider_remote_directory" + end + + Cucumber::Rake::Task.new(:git) do |t| + t.profile = "provider_git" + end + + namespace :package do + desc "Run cucumber tests for macports packages" + Cucumber::Rake::Task.new(:macports) do |t| + t.profile = "provider_package_macports" + end + + Cucumber::Rake::Task.new(:gems) do |g| + g.profile = "provider_package_rubygems" + end end end end +rescue LoadError + STDERR.puts "\n*** Cucumber is missing. (sudo) gem install cucumber to run integration tests. ***\n\n" end diff --git a/chef-solr/Rakefile b/chef-solr/Rakefile index 1c87fd267a..349857c306 100644 --- a/chef-solr/Rakefile +++ b/chef-solr/Rakefile @@ -1,3 +1,22 @@ +# +# Author:: Adam Jacob () +# Author:: Daniel DeLeo () +# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# + require 'rubygems' require 'rake' @@ -26,29 +45,33 @@ rescue LoadError puts "Jeweler (or a dependency) not available. Install it from gemcutter with: sudo gem install gemcutter jeweler" end -require 'spec/rake/spectask' -Spec::Rake::SpecTask.new(:spec) do |spec| - spec.libs << 'lib' << 'spec' - spec.spec_files = FileList['spec/**/*_spec.rb'] - spec.spec_opts = ['--options', File.expand_path(File.dirname(__FILE__) + '/spec/spec.opts')] -end +begin + require 'spec/rake/spectask' + Spec::Rake::SpecTask.new(:spec) do |spec| + spec.libs << 'lib' << 'spec' + spec.spec_files = FileList['spec/**/*_spec.rb'] + spec.spec_opts = ['--options', File.expand_path(File.dirname(__FILE__) + '/spec/spec.opts')] + end -Spec::Rake::SpecTask.new(:rcov) do |spec| - spec.libs << 'lib' << 'spec' - spec.pattern = 'spec/**/*_spec.rb' - spec.rcov = true -end + Spec::Rake::SpecTask.new(:rcov) do |spec| + spec.libs << 'lib' << 'spec' + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true + end -begin - require 'cucumber/rake/task' - Cucumber::Rake::Task.new(:features) -rescue LoadError - task :features do - abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber" + begin + require 'cucumber/rake/task' + Cucumber::Rake::Task.new(:features) + rescue LoadError + task :features do + abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber" + end end -end -task :default => :spec + task :default => :spec +rescue LoadError + STDERR.puts "\n*** rspec not available. (sudo) gem install rspec to run unit tests. ***\n\n" +end require 'rake/rdoctask' Rake::RDocTask.new do |rdoc| diff --git a/chef/Rakefile b/chef/Rakefile index 63f630c2fa..157d615901 100644 --- a/chef/Rakefile +++ b/chef/Rakefile @@ -1,3 +1,22 @@ +# +# Author:: Adam Jacob () +# Author:: Daniel DeLeo () +# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# + require 'rubygems' require 'rake/gempackagetask' require 'rake/rdoctask' diff --git a/chef/tasks/rspec.rb b/chef/tasks/rspec.rb index 45a6faa1c6..d73d3f42c5 100644 --- a/chef/tasks/rspec.rb +++ b/chef/tasks/rspec.rb @@ -1,46 +1,70 @@ +# +# Author:: Adam Jacob () +# Author:: Daniel DeLeo () +# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# + require 'rubygems' require 'rake' -require 'spec/rake/spectask' CHEF_ROOT = File.join(File.dirname(__FILE__), "..") -task :default => :spec +begin + require 'spec/rake/spectask' -desc "Run all specs in spec directory" -Spec::Rake::SpecTask.new(:spec) do |t| - t.spec_opts = ['--format', 'specdoc', '--options', "\"#{CHEF_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] -end + task :default => :spec -namespace :spec do - desc "Run all specs in spec directory with RCov" - Spec::Rake::SpecTask.new(:rcov) do |t| - t.spec_opts = ['--options', "\"#{CHEF_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] - t.rcov = true - t.rcov_opts = lambda do - IO.readlines("#{CHEF_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten - end - end - - desc "Print Specdoc for all specs" - Spec::Rake::SpecTask.new(:doc) do |t| - t.spec_opts = ["--format", "specdoc", "--dry-run"] + desc "Run all specs in spec directory" + Spec::Rake::SpecTask.new(:spec) do |t| + t.spec_opts = ['--format', 'specdoc', '--options', "\"#{CHEF_ROOT}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] end - [:unit].each do |sub| - desc "Run the specs under spec/#{sub}" - Spec::Rake::SpecTask.new(sub) do |t| + namespace :spec do + desc "Run all specs in spec directory with RCov" + Spec::Rake::SpecTask.new(:rcov) do |t| t.spec_opts = ['--options', "\"#{CHEF_ROOT}/spec/spec.opts\""] - t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] + t.spec_files = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_opts = lambda do + IO.readlines("#{CHEF_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten + end end - end - desc "Translate/upgrade specs using the built-in translator" - task :translate do - translator = ::Spec::Translator.new - dir = CHEF_ROOT + '/spec' - translator.translate(dir, dir) + desc "Print Specdoc for all specs" + Spec::Rake::SpecTask.new(:doc) do |t| + t.spec_opts = ["--format", "specdoc", "--dry-run"] + t.spec_files = FileList['spec/**/*_spec.rb'] + end + + [:unit].each do |sub| + desc "Run the specs under spec/#{sub}" + Spec::Rake::SpecTask.new(sub) do |t| + t.spec_opts = ['--options', "\"#{CHEF_ROOT}/spec/spec.opts\""] + t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] + end + end + + desc "Translate/upgrade specs using the built-in translator" + task :translate do + translator = ::Spec::Translator.new + dir = CHEF_ROOT + '/spec' + translator.translate(dir, dir) + end end -end +rescue LoadError + STDERR.puts "\n*** Rspec not available. (sudo) gem install rspec to run unit tests. ***\n\n" +end \ No newline at end of file -- cgit v1.2.1