Update for new gem version of puppetlabs_spec_helper
This updates the Rakefile and spec_helper to use the common versions available in the puppetlabs_spec_helper rubygem branch. This mostly just removes a bunch of duplicated code, but it also gives us more flexibility in how the module is tested in the future.
This commit is contained in:
parent
cf7ac02860
commit
2247df4f6e
9 changed files with 26 additions and 220 deletions
5
.gemfile
Normal file
5
.gemfile
Normal file
|
@ -0,0 +1,5 @@
|
|||
source :rubygems
|
||||
|
||||
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
|
||||
gem 'puppet', puppetversion
|
||||
gem 'puppet_module_spec_helper', :git => 'git://github.com/branan/puppetlabs_spec_helper'
|
16
.travis.yml
Normal file
16
.travis.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
language: ruby
|
||||
rvm:
|
||||
- 1.8.7
|
||||
before_script:
|
||||
after_script:
|
||||
script: "rake spec_full"
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
env:
|
||||
- PUPPET_VERSION=2.7.13
|
||||
- PUPPET_VERSION=2.7.6
|
||||
- PUPPET_VERSION=2.6.9
|
||||
notifications:
|
||||
email: false
|
||||
gemfile: .gemfile
|
18
Rakefile
18
Rakefile
|
@ -1,16 +1,2 @@
|
|||
require 'rake'
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
task :default => [:test]
|
||||
|
||||
desc 'Run RSpec'
|
||||
RSpec::Core::RakeTask.new(:test) do |t|
|
||||
t.pattern = 'spec/{unit}/**/*.rb'
|
||||
t.rspec_opts = ['--color']
|
||||
end
|
||||
|
||||
desc 'Generate code coverage'
|
||||
RSpec::Core::RakeTask.new(:coverage) do |t|
|
||||
t.rcov = true
|
||||
t.rcov_opts = ['--exclude', 'spec']
|
||||
end
|
||||
require 'rubygems'
|
||||
require 'puppet_module_spec_helper/rake_tasks'
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
require 'fileutils'
|
||||
require 'tempfile'
|
||||
|
||||
# A support module for testing files.
|
||||
module PuppetSpec::Files
|
||||
# This code exists only to support tests that run as root, pretty much.
|
||||
# Once they have finally been eliminated this can all go... --daniel 2011-04-08
|
||||
if Puppet.features.posix? then
|
||||
def self.in_tmp(path)
|
||||
path =~ /^\/tmp/ or path =~ /^\/var\/folders/
|
||||
end
|
||||
elsif Puppet.features.microsoft_windows?
|
||||
def self.in_tmp(path)
|
||||
tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp"))
|
||||
path =~ /^#{tempdir}/
|
||||
end
|
||||
else
|
||||
fail "Help! Can't find in_tmp for this platform"
|
||||
end
|
||||
|
||||
def self.cleanup
|
||||
$global_tempfiles ||= []
|
||||
while path = $global_tempfiles.pop do
|
||||
fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
|
||||
|
||||
begin
|
||||
FileUtils.rm_r path, :secure => true
|
||||
rescue Errno::ENOENT
|
||||
# nothing to do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tmpfile(name)
|
||||
# Generate a temporary file, just for the name...
|
||||
source = Tempfile.new(name)
|
||||
path = source.path
|
||||
source.close!
|
||||
|
||||
# ...record it for cleanup,
|
||||
$global_tempfiles ||= []
|
||||
$global_tempfiles << File.expand_path(path)
|
||||
|
||||
# ...and bam.
|
||||
path
|
||||
end
|
||||
|
||||
def tmpdir(name)
|
||||
path = tmpfile(name)
|
||||
FileUtils.mkdir_p(path)
|
||||
path
|
||||
end
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
module PuppetSpec::Fixtures
|
||||
def fixtures(*rest)
|
||||
File.join(PuppetSpec::FIXTURE_DIR, *rest)
|
||||
end
|
||||
def my_fixture_dir
|
||||
callers = caller
|
||||
while line = callers.shift do
|
||||
next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
|
||||
return fixtures(found[1])
|
||||
end
|
||||
fail "sorry, I couldn't work out your path from the caller stack!"
|
||||
end
|
||||
def my_fixture(name)
|
||||
file = File.join(my_fixture_dir, name)
|
||||
unless File.readable? file then
|
||||
fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable"
|
||||
end
|
||||
return file
|
||||
end
|
||||
def my_fixtures(glob = '*', flags = 0)
|
||||
files = Dir.glob(File.join(my_fixture_dir, glob), flags)
|
||||
unless files.length > 0 then
|
||||
fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!"
|
||||
end
|
||||
block_given? and files.each do |file| yield file end
|
||||
files
|
||||
end
|
||||
end
|
|
@ -1,87 +0,0 @@
|
|||
require 'stringio'
|
||||
|
||||
########################################################################
|
||||
# Backward compatibility for Jenkins outdated environment.
|
||||
module RSpec
|
||||
module Matchers
|
||||
module BlockAliases
|
||||
alias_method :to, :should unless method_defined? :to
|
||||
alias_method :to_not, :should_not unless method_defined? :to_not
|
||||
alias_method :not_to, :should_not unless method_defined? :not_to
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Custom matchers...
|
||||
RSpec::Matchers.define :have_matching_element do |expected|
|
||||
match do |actual|
|
||||
actual.any? { |item| item =~ expected }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
RSpec::Matchers.define :exit_with do |expected|
|
||||
actual = nil
|
||||
match do |block|
|
||||
begin
|
||||
block.call
|
||||
rescue SystemExit => e
|
||||
actual = e.status
|
||||
end
|
||||
actual and actual == expected
|
||||
end
|
||||
failure_message_for_should do |block|
|
||||
"expected exit with code #{expected} but " +
|
||||
(actual.nil? ? " exit was not called" : "we exited with #{actual} instead")
|
||||
end
|
||||
failure_message_for_should_not do |block|
|
||||
"expected that exit would not be called with #{expected}"
|
||||
end
|
||||
description do
|
||||
"expect exit with #{expected}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
RSpec::Matchers.define :have_printed do |expected|
|
||||
match do |block|
|
||||
$stderr = $stdout = StringIO.new
|
||||
|
||||
begin
|
||||
block.call
|
||||
ensure
|
||||
$stdout.rewind
|
||||
@actual = $stdout.read
|
||||
|
||||
$stdout = STDOUT
|
||||
$stderr = STDERR
|
||||
end
|
||||
|
||||
if @actual then
|
||||
case expected
|
||||
when String
|
||||
@actual.include? expected
|
||||
when Regexp
|
||||
expected.match @actual
|
||||
else
|
||||
raise ArgumentError, "No idea how to match a #{@actual.class.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
failure_message_for_should do |actual|
|
||||
if actual.nil? then
|
||||
"expected #{expected.inspect}, but nothing was printed"
|
||||
else
|
||||
"expected #{expected.inspect} to be printed; got:\n#{actual}"
|
||||
end
|
||||
end
|
||||
|
||||
description do
|
||||
"expect #{expected.inspect} to be printed"
|
||||
end
|
||||
|
||||
diffable
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
# Support code for running stuff with warnings disabled.
|
||||
module Kernel
|
||||
def with_verbose_disabled
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
result = yield
|
||||
$VERBOSE = verbose
|
||||
return result
|
||||
end
|
||||
end
|
|
@ -1,28 +1,4 @@
|
|||
dir = File.expand_path(File.dirname(__FILE__))
|
||||
$LOAD_PATH.unshift File.join(dir, 'lib')
|
||||
|
||||
# Don't want puppet getting the command line arguments for rake or autotest
|
||||
ARGV.clear
|
||||
|
||||
require 'puppet'
|
||||
require 'facter'
|
||||
require 'mocha'
|
||||
gem 'rspec', '>=2.0.0'
|
||||
require 'rspec/expectations'
|
||||
|
||||
|
||||
# So everyone else doesn't have to include this base constant.
|
||||
module PuppetSpec
|
||||
FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
|
||||
end
|
||||
|
||||
# TODO: ultimately would like to move these requires into the puppet_spec_helper.rb file, but the namespaces
|
||||
# are not currently the same between the two, so tests would need to be modified. Not ready to undertake that
|
||||
# just yet.
|
||||
require 'puppet_spec/files'
|
||||
|
||||
require 'puppet_spec_helper'
|
||||
|
||||
require 'puppet_module_spec_helper/puppet_spec_helper'
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'puppet'
|
|||
require 'fileutils'
|
||||
require 'spec_helper'
|
||||
describe Puppet::Parser::Functions.function(:get_module_path) do
|
||||
include PuppetSpec::Files
|
||||
include PuppetlabsSpec::Files
|
||||
|
||||
def get_scope(environment = 'production')
|
||||
scope = Puppet::Parser::Scope.new
|
||||
|
@ -30,7 +30,7 @@ describe Puppet::Parser::Functions.function(:get_module_path) do
|
|||
get_scope.function_get_module_path(['foo']).should == foo_path
|
||||
end
|
||||
it 'should be able to find module paths from the environment' do
|
||||
conf_file = tmpfile('conffile')
|
||||
conf_file = tmpfilename('conffile')
|
||||
File.open(conf_file, 'w') do |fh|
|
||||
fh.write("[dansenvironment]\nmodulepath = #{modulepath}")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue