]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/lib/puppet_spec/fixtures.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / lib / puppet_spec / fixtures.rb
1 #! /usr/bin/env ruby -S rspec
2 module PuppetSpec::Fixtures
3   def fixtures(*rest)
4     File.join(PuppetSpec::FIXTURE_DIR, *rest)
5   end
6   def my_fixture_dir
7     callers = caller
8     while line = callers.shift do
9       next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
10       return fixtures(found[1])
11     end
12     fail "sorry, I couldn't work out your path from the caller stack!"
13   end
14   def my_fixture(name)
15     file = File.join(my_fixture_dir, name)
16     unless File.readable? file then
17       fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable"
18     end
19     return file
20   end
21   def my_fixtures(glob = '*', flags = 0)
22     files = Dir.glob(File.join(my_fixture_dir, glob), flags)
23     unless files.length > 0 then
24       fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!"
25     end
26     block_given? and files.each do |file| yield file end
27     files
28   end
29 end