Update new modulefile template
These changes make spec testing easier for humans and computers * Add `rake spec_full` and friends * Remove recursive symlink * Prepend fixtures modulepath instead of overriding * Update travis config to use spec_full
This commit is contained in:
parent
5c359e0f06
commit
297d77ebb7
6
deployment/puppet/rabbitmq/.fixtures.yml
Normal file
6
deployment/puppet/rabbitmq/.fixtures.yml
Normal file
@ -0,0 +1,6 @@
|
||||
fixtures:
|
||||
repositories:
|
||||
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
|
||||
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
|
||||
symlinks:
|
||||
"rabbitmq": "#{source_dir}"
|
@ -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 && git clone git://github.com/puppetlabs/puppet-apt.git spec/fixtures/modules/apt"
|
||||
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
|
||||
|
@ -1,5 +1,6 @@
|
||||
require 'rake'
|
||||
require 'rspec/core/rake_task'
|
||||
require 'yaml'
|
||||
|
||||
task :default => [:spec]
|
||||
|
||||
@ -9,6 +10,62 @@ 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
|
||||
|
||||
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.
|
||||
@ -21,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
|
||||
|
@ -1,18 +1,18 @@
|
||||
require 'pathname'
|
||||
dir = Pathname.new(__FILE__).parent
|
||||
$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
|
||||
|
||||
require 'mocha'
|
||||
require 'rubygems'
|
||||
require 'puppet'
|
||||
gem 'rspec', '=1.2.9'
|
||||
require 'spec/autorun'
|
||||
require 'rspec-puppet'
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
config.mock_with :mocha
|
||||
def param_value(subject, type, title, param)
|
||||
subject.resource(type, title).send(:parameters)[param.to_sym]
|
||||
end
|
||||
|
||||
# We need this because the RAL uses 'should' as a method. This
|
||||
# allows us the same behaviour but with a different method name.
|
||||
class Object
|
||||
alias :must :should
|
||||
Puppet.parse_config
|
||||
puppet_module_path = Puppet[:modulepath]
|
||||
|
||||
fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
||||
|
||||
RSpec.configure do |c|
|
||||
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')
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user