summaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@rimspace.net>2011-03-02 21:54:40 -0800
committerDaniel Pittman <daniel@rimspace.net>2011-03-03 16:29:07 -0800
commit6b8f1b724d08e62af6fcf6a2ea55d72b74876de3 (patch)
tree642026e4b9db04b426e76d3f2d852eb7f54f9020 /spec/lib
parent7c9f1b803d86ead714ff90770e0ccc87ab29efbc (diff)
downloadpuppet-6b8f1b724d08e62af6fcf6a2ea55d72b74876de3.tar.gz
puppet-6b8f1b724d08e62af6fcf6a2ea55d72b74876de3.tar.xz
puppet-6b8f1b724d08e62af6fcf6a2ea55d72b74876de3.zip
(#6582) add fixture helper methods to replace unit test code.
We validate that fixtures exist, when requested, or that they match something when they use a glob. This catches internal errors where we don't match any fixtures with a glob; this can reveal problems that would otherwise avoid all assertions and result in internal failures. The code is hidden out in a module, included in the main RSpec namespace. This doesn't clean up the API any, but it isolates the code more effectively and keeps the configuration file cleaner. Reviewed-By: Nick Lewis <nick@puppetlabs.com>
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/puppet_spec/fixtures.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb
new file mode 100644
index 000000000..96bb1e39d
--- /dev/null
+++ b/spec/lib/puppet_spec/fixtures.rb
@@ -0,0 +1,28 @@
+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{puppet/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