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