summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-06 16:23:28 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-06 16:29:57 -0700
commit07a79cf4f2b62250049fb9b52d7d310d3e0ab5d2 (patch)
tree4f77c2438412744c95d68e6bd5a20402b7bb630c
parenta1a09b086dc19ad5257599f24ef8d92bfcabc11e (diff)
downloadpuppet-07a79cf4f2b62250049fb9b52d7d310d3e0ab5d2.tar.gz
puppet-07a79cf4f2b62250049fb9b52d7d310d3e0ab5d2.tar.xz
puppet-07a79cf4f2b62250049fb9b52d7d310d3e0ab5d2.zip
maint: add `write_scratch_string` helper for testing...
We had a pattern where we wanted to routinely write scratch strings to disk, on the load path, so we could reference them later. This extracts that into a helper, and starts to use it in tests that should follow that pattern. Reviewed-By: Dan Bode <dan@puppetlabs.com>
-rw-r--r--spec/spec_helper.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3b04636f3..bb71fca73 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -26,7 +26,9 @@ RSpec.configure do |config|
@logs = []
Puppet::Util::Log.newdestination(@logs)
-
+ @load_path_scratch_dir = Dir.mktmpdir
+ $LOAD_PATH.push @load_path_scratch_dir
+ FileUtils.mkdir_p(File.join @load_path_scratch_dir, 'puppet', 'string')
end
config.after :each do
@@ -34,6 +36,18 @@ RSpec.configure do |config|
@logs.clear
Puppet::Util::Log.close_all
+
+ $LOAD_PATH.delete @load_path_scratch_dir
+ FileUtils.remove_entry_secure @load_path_scratch_dir
+ end
+
+ def write_scratch_string(name)
+ fail "you need to supply a block: do |fh| fh.puts 'content' end" unless block_given?
+ fail "name should be a symbol" unless name.is_a? Symbol
+ filename = File.join(@load_path_scratch_dir, 'puppet', 'string', "#{name}.rb")
+ File.open(filename, 'w') do |fh|
+ yield fh
+ end
end
end