We had a common pattern for creating a temporary
file during integration tests, and this just
makes that common pattern explicit by
moving it to a module in the newly-created
lib directory in the spec directory.

We definitely don't want to go overboard in
using libraries in our tests, but sometimes
it gets a bit excessive to completely avoid them.

Signed-off-by: Luke Kanies <[email protected]>
---
 spec/integration/type/file.rb     |    9 +++------
 spec/integration/type/tidy.rb     |    9 +++------
 spec/integration/util/settings.rb |    9 +++------
 spec/lib/puppet_spec/files.rb     |    9 +++++++++
 spec/spec_helper.rb               |    5 +++++
 5 files changed, 23 insertions(+), 18 deletions(-)
 create mode 100644 spec/lib/puppet_spec/files.rb

diff --git a/spec/integration/type/file.rb b/spec/integration/type/file.rb
index 87a478d..ef0cd39 100755
--- a/spec/integration/type/file.rb
+++ b/spec/integration/type/file.rb
@@ -2,13 +2,10 @@
 
 require File.dirname(__FILE__) + '/../../spec_helper'
 
+require 'puppet_spec/files'
+
 describe Puppet::Type.type(:file) do
-    def tmpfile(name)
-        source = Tempfile.new(name)
-        path = source.path
-        source.close!
-        path
-    end
+    include PuppetSpec::Files
 
     describe "when recursing" do
         def build_path(dir)
diff --git a/spec/integration/type/tidy.rb b/spec/integration/type/tidy.rb
index 50ec3d7..c2206f9 100755
--- a/spec/integration/type/tidy.rb
+++ b/spec/integration/type/tidy.rb
@@ -2,13 +2,10 @@
 
 require File.dirname(__FILE__) + '/../../spec_helper'
 
+require 'puppet_spec/files'
+
 describe Puppet::Type.type(:tidy) do
-    def tmpfile(name)
-        source = Tempfile.new(name)
-        path = source.path
-        source.close!
-        path
-    end
+    include PuppetSpec::Files
 
     # Testing #355.
     it "should be able to remove dead links" do
diff --git a/spec/integration/util/settings.rb 
b/spec/integration/util/settings.rb
index d2fe868..146b988 100755
--- a/spec/integration/util/settings.rb
+++ b/spec/integration/util/settings.rb
@@ -2,13 +2,10 @@
 
 require File.dirname(__FILE__) + '/../../spec_helper'
 
+require 'puppet_spec/files'
+
 describe Puppet::Util::Settings do
-    def tmpfile(name)
-        source = Tempfile.new(name)
-        path = source.path
-        source.close!
-        path
-    end
+    include PuppetSpec::Files
 
     it "should be able to make needed directories" do
         settings = Puppet::Util::Settings.new
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
new file mode 100644
index 0000000..542ad6e
--- /dev/null
+++ b/spec/lib/puppet_spec/files.rb
@@ -0,0 +1,9 @@
+# A support module for testing files.
+module PuppetSpec::Files
+    def tmpfile(name)
+        source = Tempfile.new(name)
+        path = source.path
+        source.close!
+        path
+    end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2f47d4f..5c7b6ee 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,6 +1,7 @@
 dir = File.expand_path(File.dirname(__FILE__))
 
 $LOAD_PATH.unshift("#{dir}/")
+$LOAD_PATH.unshift("#{dir}/lib") # a spec-specific test lib dir
 $LOAD_PATH.unshift("#{dir}/../lib")
 $LOAD_PATH.unshift("#{dir}/../test/lib")  # Add the old test dir, so that we 
can still find our local mocha and spec
 
@@ -20,6 +21,10 @@ require 'mocha'
 gem 'rspec', '=1.2.2'
 require 'spec/autorun'
 
+# So everyone else doesn't have to include this base constant.
+module PuppetSpec
+end
+
 # load any monkey-patches
 Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file }
 
-- 
1.6.1


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to