Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reimplement puppetlabs_spec_helper rake tasks

I'm stubborn.
  • Loading branch information...
commit 02803225e41f68632f2e5098cc94bc4156ddffe4 1 parent 36b19cd
@adrienthebo adrienthebo authored
Showing with 67 additions and 8 deletions.
  1. +7 −0 .fixtures.yml
  2. +48 −0 Rakefile
  3. +12 −8 spec/spec_helper.rb
View
7 .fixtures.yml
@@ -0,0 +1,7 @@
+---
+fixtures:
+ repositories:
+ kmod: 'https://github.com/camptocamp/puppet-kmod'
+ stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib'
+ boolean: 'https://github.com/adrienthebo/puppet-boolean'
+ filemapper: 'https://github.com/adrienthebo/puppet-filemapper'
View
48 Rakefile
@@ -0,0 +1,48 @@
+require 'rake'
+require 'yaml'
+require 'rspec/core/rake_task'
+
+def fixtures(category)
+ root = File.dirname(__FILE__)
+ yaml = YAML.load_file(File.expand_path('.fixtures.yml', root))
+
+ fixtures = yaml["fixtures"]
+
+ if fixtures.nil?
+ raise ".fixtures.yml contained no top level 'fixtures' key"
+ end
+
+ fixtures[category] || {}
+rescue => e
+ raise e, "Could not load fixture data: #{e}"
+end
+
+namespace :fixture do
+
+ desc "Prepare all fixture repositories"
+ task :prepare do
+ fixtures("repositories").each_pair do |name, remote|
+ fixture_target = "spec/fixtures/modules/#{name}"
+ sh "git clone '#{remote}' '#{fixture_target}'" unless File.exist? fixture_target
+ end
+ end
+
+ desc "Remove all fixture repositories"
+ task :remove do
+ fixtures["repositories"].each_pair do |name, remote|
+ fixture_target = "spec/fixtures/modules/#{name}"
+ FileUtils.rm_rf fixture_target if File.exist? fixture_target
+ end
+ end
+end
+
+desc "Run spec tests on an existing fixtures directory"
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.rspec_opts = ['--color']
+ t.pattern = 'spec/{classes,defines,unit,functions,hosts}/**/*_spec.rb'
+end
+
+desc "Display the list of available rake tasks"
+task :help do
+ system("rake -T")
+end
View
20 spec/spec_helper.rb
@@ -1,20 +1,24 @@
+require 'rspec'
require 'puppet'
require 'rspec-puppet'
require 'mocha'
-PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+PROJECT_ROOT = File.expand_path('..', File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(PROJECT_ROOT, "lib"))
+fixture_path = File.expand_path(File.join('spec', 'fixtures'), PROJECT_ROOT)
+
RSpec.configure do |config|
config.mock_with :mocha
+
+ # ---
+ # Configuration for puppet-rspec
+
+ config.module_path = File.join(fixture_path, 'modules')
+ config.manifest_dir = File.join(fixture_path, 'manifests')
end
# ---
-# Configuration for puppet-rspec
+# Add the fixture module libdirs to the modulepath
-fixture_path = File.expand_path('fixtures', File.dirname(__FILE__))
-
-RSpec.configure do |c|
- c.module_path = File.join(fixture_path, 'modules')
- c.manifest_dir = File.join(fixture_path, 'manifests')
-end
+$LOAD_PATH.concat(Dir.glob(File.join(fixture_path, 'modules', '*', 'lib')))
Please sign in to comment.
Something went wrong with that request. Please try again.