From 6bdc09719a58e83c9f4fd17832540807f446838a Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Fri, 25 May 2012 12:07:36 -0700 Subject: Update for the new module template * Add `rake spec_full` and friends * Remove recursive symlink * Prepend fixtures modulepath instead of overriding * Update travis config to use spec_full --- .fixtures.yml | 5 ++++ .gemfile | 13 +++++++++ .travis.yml | 4 +-- Gemfile | 13 --------- Rakefile | 72 ++++++++++++++++++++++++++++++++++++++++------ spec/fixtures/modules/tftp | 1 - spec/spec_helper.rb | 19 ++++++------ 7 files changed, 94 insertions(+), 33 deletions(-) create mode 100644 .fixtures.yml create mode 100644 .gemfile delete mode 100644 Gemfile delete mode 120000 spec/fixtures/modules/tftp diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..a38b2cb --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,5 @@ +fixtures: + repositories: + "inetd": "git://github.com/puppetlabs/puppetlabs-inetd.git" + symlinks: + "tftp": "#{source_dir}" diff --git a/.gemfile b/.gemfile new file mode 100644 index 0000000..7ba9ef9 --- /dev/null +++ b/.gemfile @@ -0,0 +1,13 @@ +source :rubygems + +puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7'] + +gem 'puppet', puppetversion + +group :test do + gem 'rake', '>= 0.9.0' + gem 'rspec', '>= 2.8.0' + gem 'rspec-puppet', '>= 0.1.1' + gem 'mocha', '>= 0.11.0' + gem 'puppet-lint', '>= 0.1.0' +end diff --git a/.travis.yml b/.travis.yml index 32d262a..0ec5a08 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-inetd.git spec/fixtures/modules/inetd" after_script: -script: "rake spec" +script: "rake spec_full" branches: only: - master @@ -14,3 +13,4 @@ env: - PUPPET_VERSION=2.6.9 notifications: email: false +gemfile: .gemfile diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 7ba9ef9..0000000 --- a/Gemfile +++ /dev/null @@ -1,13 +0,0 @@ -source :rubygems - -puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7'] - -gem 'puppet', puppetversion - -group :test do - gem 'rake', '>= 0.9.0' - gem 'rspec', '>= 2.8.0' - gem 'rspec-puppet', '>= 0.1.1' - gem 'mocha', '>= 0.11.0' - gem 'puppet-lint', '>= 0.1.0' -end diff --git a/Rakefile b/Rakefile index 6f28836..ab25667 100644 --- a/Rakefile +++ b/Rakefile @@ -1,20 +1,71 @@ -require 'rubygems' require 'rake' require 'rspec/core/rake_task' +require 'yaml' -task :default do - system("rake -T") -end - -task :specs => [:spec] +task :default => [:spec] -desc "Run all rspec-puppet tests" +desc "Run all module spec tests (Requires rspec-puppet gem)" RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = ['--color'] - # ignores fixtures directory. 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 + + FileUtils::mkdir_p("spec/fixtures/modules") + 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. @@ -27,6 +78,11 @@ task :build do end end +desc "Clean a built module package" +task :clean do + FileUtils.rm_rf("pkg/") +end + desc "Check puppet manifests with puppet-lint" task :lint do # This requires pull request: https://github.com/rodjek/puppet-lint/pull/81 diff --git a/spec/fixtures/modules/tftp b/spec/fixtures/modules/tftp deleted file mode 120000 index 1b20c9f..0000000 --- a/spec/fixtures/modules/tftp +++ /dev/null @@ -1 +0,0 @@ -../../../ \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b47eaea..efff5b4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,20 +1,21 @@ +require 'rubygems' require 'puppet' -require 'mocha' -require 'rspec' require 'rspec-puppet' -require 'rspec/expectations' +require 'mocha' require 'puppetlabs_spec_helper' def param_value(subject, type, title, param) subject.resource(type, title).send(:parameters)[param.to_sym] end +Puppet.parse_config +puppet_module_path = Puppet[:modulepath] + +fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) + RSpec.configure do |c| - c.module_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/modules')) - # Using an empty site.pp file to avoid: https://github.com/rodjek/rspec-puppet/issues/15 - c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests')) - # Use fixtures for config file mainly to support using our own hiera.yaml settings. - # Pending: https://github.com/rodjek/rspec-puppet/pull/21 - # c.config = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/puppet.conf')) + fixture_module_path = File.join(fixture_path, 'modules') + c.module_path = [fixture_module_path, puppet_module_path].join(":") + c.manifest_dir = File.join(fixture_path, 'manifests') c.mock_with :mocha end -- cgit v1.2.3