diff --git a/Rakefile b/Rakefile index a86d95fd7..632542d83 100644 --- a/Rakefile +++ b/Rakefile @@ -1,62 +1,13 @@ require 'rubygems' require 'bundler/setup' -require 'rake/testtask' -require 'rspec/core/rake_task' -Bundler::GemHelper.install_tasks + +# Load all the rake tasks from the "tasks" folder. This folder +# allows us to nicely separate rake tasks into individual files +# based on their role, which makes development and debugging easier +# than one monolithic file. +task_dir = File.expand_path("../tasks", __FILE__) +Dir["#{task_dir}/**/*.rake"].each do |task_file| + load task_file +end task :default => "test:unit" - -namespace :test do - Rake::TestTask.new do |t| - t.name = "unit" - t.libs << "test/unit" - t.pattern = "test/unit/**/*_test.rb" - end - - RSpec::Core::RakeTask.new do |t| - t.name = "acceptance" - t.pattern = "test/acceptance/**/*_test.rb" - end -end - -namespace :acceptance do - desc "Generates the configuration for acceptance tests from current source." - task :config do - require 'yaml' - require 'posix-spawn' - - require File.expand_path("../lib/vagrant/version", __FILE__) - require File.expand_path('../test/acceptance/support/tempdir', __FILE__) - - # Generate the binstubs for the Vagrant binary - tempdir = Tempdir.new - pid, stdin, stdout, stderr = - POSIX::Spawn.popen4("bundle", "install", "--binstubs", tempdir.path) - pid, status = Process.waitpid2(pid) - if status.exitstatus != 0 - # Bundle install failed... - puts "Bundle install failed! Error:" - puts stderr.read - exit 1 - end - - # Generate the actual configuration - config = { - "vagrant_path" => File.join(tempdir.path, "vagrant"), - "vagrant_version" => Vagrant::VERSION, - "env" => { - "BUNDLE_GEMFILE" => File.expand_path("../Gemfile", __FILE__) - } - } - - File.open("acceptance_config.yml", "w+") do |f| - f.write(YAML.dump(config)) - end - - puts <<-OUTPUT -Acceptance test configuration is now in this directory in -"acceptance_config.yml." Set your ACCEPTANCE_CONFIG environmental -variable to this file and run any of the acceptance tests now. -OUTPUT - end -end diff --git a/tasks/acceptance.rake b/tasks/acceptance.rake new file mode 100644 index 000000000..d807666d5 --- /dev/null +++ b/tasks/acceptance.rake @@ -0,0 +1,41 @@ +namespace :acceptance do + desc "Generates the configuration for acceptance tests from current source." + task :config do + require 'yaml' + require 'posix-spawn' + + require File.expand_path("../lib/vagrant/version", __FILE__) + require File.expand_path('../test/acceptance/support/tempdir', __FILE__) + + # Generate the binstubs for the Vagrant binary + tempdir = Tempdir.new + pid, stdin, stdout, stderr = + POSIX::Spawn.popen4("bundle", "install", "--binstubs", tempdir.path) + pid, status = Process.waitpid2(pid) + if status.exitstatus != 0 + # Bundle install failed... + puts "Bundle install failed! Error:" + puts stderr.read + exit 1 + end + + # Generate the actual configuration + config = { + "vagrant_path" => File.join(tempdir.path, "vagrant"), + "vagrant_version" => Vagrant::VERSION, + "env" => { + "BUNDLE_GEMFILE" => File.expand_path("../Gemfile", __FILE__) + } + } + + File.open("acceptance_config.yml", "w+") do |f| + f.write(YAML.dump(config)) + end + + puts <<-OUTPUT +Acceptance test configuration is now in this directory in +"acceptance_config.yml." Set your ACCEPTANCE_CONFIG environmental +variable to this file and run any of the acceptance tests now. +OUTPUT + end +end diff --git a/tasks/bundler.rake b/tasks/bundler.rake new file mode 100644 index 000000000..16cf8ac0b --- /dev/null +++ b/tasks/bundler.rake @@ -0,0 +1,3 @@ +# This installs the tasks that help with gem creation and +# publishing. +Bundler::GemHelper.install_tasks diff --git a/tasks/test.rake b/tasks/test.rake new file mode 100644 index 000000000..673d7707a --- /dev/null +++ b/tasks/test.rake @@ -0,0 +1,15 @@ +require 'rake/testtask' +require 'rspec/core/rake_task' + +namespace :test do + Rake::TestTask.new do |t| + t.name = "unit" + t.libs << "test/unit" + t.pattern = "test/unit/**/*_test.rb" + end + + RSpec::Core::RakeTask.new do |t| + t.name = "acceptance" + t.pattern = "test/acceptance/**/*_test.rb" + end +end