From 07a79cf4f2b62250049fb9b52d7d310d3e0ab5d2 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 6 Apr 2011 16:23:28 -0700 Subject: 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 --- spec/spec_helper.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 -- cgit