From: Branan Purvine-Riley Date: Tue, 22 May 2012 20:10:30 +0000 (-0700) Subject: add spec_prep, spec_clean, and spec_full rake tasks X-Git-Tag: 0.0.4~11^2~1 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f420cb6314ad13e213c113cda08d7ea79b00b856;p=puppet-modules%2Fpuppetlabs-apt.git add spec_prep, spec_clean, and spec_full rake tasks These targets automate the fixtures directory using a configuration stored in fixtures.yml. Because we can now handle the fixtures directory with a rake task, the clone commands have been removed from the Travis config. --- diff --git a/.travis.yml b/.travis.yml index a4ec2c1..8fa95c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,8 @@ language: ruby rvm: - 1.8.7 before_script: - - "git clone git://github.com/puppetlabs/puppetlabs-stdlib.git spec/fixtures/modules/stdlib" after_script: -script: "rake spec" +script: "rake spec_full" branches: only: - master diff --git a/Rakefile b/Rakefile index 5cbef6b..4810519 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ require 'rake' require 'rspec/core/rake_task' +require 'yaml' task :default => [:spec] @@ -9,6 +10,61 @@ RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = 'spec/{classes,defines,unit}/**/*_spec.rb' end +# This is a helper for the self-symlink entry of fixtures.yml +def source_dir + File.dirname(__FILE__) +end + +def fixtures(category) + begin + fixtures = YAML.load_file("fixtures.yml")["fixtures"] + rescue Errno::ENOENT + return {} + end + + if not fixtures + abort("malformed fixtures.yml") + end + + result = {} + if fixtures.include? category + fixtures[category].each do |fixture, source| + target = "spec/fixtures/modules/#{fixture}" + real_source = eval('"'+source+'"') + result[real_source] = target + end + end + return result +end + +desc "Create the fixtures directory" +task :spec_prep do + fixtures("repositories").each do |repo, target| + File::exists?(target) || system("git clone #{repo} #{target}") + end + + fixtures("symlinks").each do |source, target| + File::exists?(target) || FileUtils::ln_s(source, target) + end +end + +desc "Clean up the fixtures directory" +task :spec_clean do + fixtures("repositories").each do |repo, target| + FileUtils::rm_rf(target) + end + + fixtures("symlinks").each do |source, target| + FileUtils::rm(target) + end +end + +task :spec_full do + Rake::Task[:spec_prep].invoke + Rake::Task[:spec].invoke + Rake::Task[:spec_clean].invoke +end + desc "Build puppet module package" task :build do # This will be deprecated once puppet-module is a face. diff --git a/fixtures.yml b/fixtures.yml new file mode 100644 index 0000000..dbd5621 --- /dev/null +++ b/fixtures.yml @@ -0,0 +1,5 @@ +fixtures: + repositories: + "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" + symlinks: + "apt": "#{source_dir}"