summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-02-18 11:44:34 -0600
committerRick Bradley <rick@rickbradley.com>2008-02-18 11:44:34 -0600
commit034336bb1d9d8a3d3220aa62eb18c796f7982f53 (patch)
tree15f87e2e382a39b990fc45b5fc427be1b93fa37a
parent12f139ce7fb040753440b37727eb5dacd0e3e1cb (diff)
downloadpuppet-034336bb1d9d8a3d3220aa62eb18c796f7982f53.tar.gz
puppet-034336bb1d9d8a3d3220aa62eb18c796f7982f53.tar.xz
puppet-034336bb1d9d8a3d3220aa62eb18c796f7982f53.zip
converting indirector file specs from setup/teardown to before/after
-rwxr-xr-xspec/unit/indirector/file.rb200
1 files changed, 99 insertions, 101 deletions
diff --git a/spec/unit/indirector/file.rb b/spec/unit/indirector/file.rb
index 216c9bfe1..37740f0d0 100755
--- a/spec/unit/indirector/file.rb
+++ b/spec/unit/indirector/file.rb
@@ -3,8 +3,9 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/indirector/file'
-module FileTerminusTesting
- def setup
+
+describe Puppet::Indirector::File do
+ before :each do
Puppet::Indirector::Terminus.stubs(:register_terminus_class)
@model = mock 'model'
@indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
@@ -21,140 +22,137 @@ module FileTerminusTesting
@path = "/my/file"
@dir = "/my"
end
-end
+
+ describe Puppet::Indirector::File, " when finding files" do
-describe Puppet::Indirector::File, " when finding files" do
- include FileTerminusTesting
+ it "should provide a method to return file contents at a specified path" do
+ @searcher.should respond_to(:find)
+ end
- it "should provide a method to return file contents at a specified path" do
- @searcher.should respond_to(:find)
- end
+ it "should return file contents as an instance of the model" do
+ content = "my content"
- it "should return file contents as an instance of the model" do
- content = "my content"
+ file = mock 'file'
+ @model.expects(:new).with(content).returns(file)
- file = mock 'file'
- @model.expects(:new).with(content).returns(file)
+ File.expects(:exist?).with(@path).returns(true)
+ File.expects(:read).with(@path).returns(content)
+ @searcher.find(@path)
+ end
- File.expects(:exist?).with(@path).returns(true)
- File.expects(:read).with(@path).returns(content)
- @searcher.find(@path)
- end
+ it "should create the model instance with the content as the only argument to initialization" do
+ content = "my content"
- it "should create the model instance with the content as the only argument to initialization" do
- content = "my content"
+ file = mock 'file'
+ @model.expects(:new).with(content).returns(file)
- file = mock 'file'
- @model.expects(:new).with(content).returns(file)
+ File.expects(:exist?).with(@path).returns(true)
+ File.expects(:read).with(@path).returns(content)
+ @searcher.find(@path).should equal(file)
+ end
- File.expects(:exist?).with(@path).returns(true)
- File.expects(:read).with(@path).returns(content)
- @searcher.find(@path).should equal(file)
- end
+ it "should return nil if no file is found" do
+ File.expects(:exist?).with(@path).returns(false)
+ @searcher.find(@path).should be_nil
+ end
- it "should return nil if no file is found" do
- File.expects(:exist?).with(@path).returns(false)
- @searcher.find(@path).should be_nil
- end
+ it "should fail intelligently if a found file cannot be read" do
+ File.expects(:exist?).with(@path).returns(true)
+ File.expects(:read).with(@path).raises(RuntimeError)
+ proc { @searcher.find(@path) }.should raise_error(Puppet::Error)
+ end
- it "should fail intelligently if a found file cannot be read" do
- File.expects(:exist?).with(@path).returns(true)
- File.expects(:read).with(@path).raises(RuntimeError)
- proc { @searcher.find(@path) }.should raise_error(Puppet::Error)
- end
+ it "should use the path() method to calculate the path if it exists" do
+ @searcher.meta_def(:path) do |name|
+ name.upcase
+ end
- it "should use the path() method to calculate the path if it exists" do
- @searcher.meta_def(:path) do |name|
- name.upcase
+ File.expects(:exist?).with(@path.upcase).returns(false)
+ @searcher.find(@path)
end
-
- File.expects(:exist?).with(@path.upcase).returns(false)
- @searcher.find(@path)
end
-end
-describe Puppet::Indirector::File, " when saving files" do
- include FileTerminusTesting
+ describe Puppet::Indirector::File, " when saving files" do
- it "should provide a method to save file contents at a specified path" do
- filehandle = mock 'file'
- content = "my content"
- File.expects(:directory?).with(@dir).returns(true)
- File.expects(:open).with(@path, "w").yields(filehandle)
- filehandle.expects(:print).with(content)
+ it "should provide a method to save file contents at a specified path" do
+ filehandle = mock 'file'
+ content = "my content"
+ File.expects(:directory?).with(@dir).returns(true)
+ File.expects(:open).with(@path, "w").yields(filehandle)
+ filehandle.expects(:print).with(content)
- file = stub 'file', :content => content, :path => @path, :name => @path
+ file = stub 'file', :content => content, :path => @path, :name => @path
- @searcher.save(file)
- end
+ @searcher.save(file)
+ end
- it "should fail intelligently if the file's parent directory does not exist" do
- File.expects(:directory?).with(@dir).returns(false)
+ it "should fail intelligently if the file's parent directory does not exist" do
+ File.expects(:directory?).with(@dir).returns(false)
- file = stub 'file', :path => @path, :name => @path
+ file = stub 'file', :path => @path, :name => @path
- proc { @searcher.save(file) }.should raise_error(Puppet::Error)
- end
-
- it "should fail intelligently if a file cannot be written" do
- filehandle = mock 'file'
- content = "my content"
- File.expects(:directory?).with(@dir).returns(true)
- File.expects(:open).with(@path, "w").yields(filehandle)
- filehandle.expects(:print).with(content).raises(ArgumentError)
+ proc { @searcher.save(file) }.should raise_error(Puppet::Error)
+ end
- file = stub 'file', :content => content, :path => @path, :name => @path
+ it "should fail intelligently if a file cannot be written" do
+ filehandle = mock 'file'
+ content = "my content"
+ File.expects(:directory?).with(@dir).returns(true)
+ File.expects(:open).with(@path, "w").yields(filehandle)
+ filehandle.expects(:print).with(content).raises(ArgumentError)
- proc { @searcher.save(file) }.should raise_error(Puppet::Error)
- end
+ file = stub 'file', :content => content, :path => @path, :name => @path
- it "should use the path() method to calculate the path if it exists" do
- @searcher.meta_def(:path) do |name|
- name.upcase
+ proc { @searcher.save(file) }.should raise_error(Puppet::Error)
end
- file = stub 'file', :name => "/yay"
+ it "should use the path() method to calculate the path if it exists" do
+ @searcher.meta_def(:path) do |name|
+ name.upcase
+ end
+
+ file = stub 'file', :name => "/yay"
- File.expects(:open).with("/YAY", "w")
- @searcher.save(file)
+ File.expects(:open).with("/YAY", "w")
+ @searcher.save(file)
+ end
end
-end
-describe Puppet::Indirector::File, " when removing files" do
- include FileTerminusTesting
+ describe Puppet::Indirector::File, " when removing files" do
- it "should provide a method to remove files at a specified path" do
- file = stub 'file', :path => @path, :name => @path
- File.expects(:exist?).with(@path).returns(true)
- File.expects(:unlink).with(@path)
-
- @searcher.destroy(file)
- end
+ it "should provide a method to remove files at a specified path" do
+ file = stub 'file', :path => @path, :name => @path
+ File.expects(:exist?).with(@path).returns(true)
+ File.expects(:unlink).with(@path)
- it "should throw an exception if the file is not found" do
- file = stub 'file', :path => @path, :name => @path
- File.expects(:exist?).with(@path).returns(false)
+ @searcher.destroy(file)
+ end
- proc { @searcher.destroy(file) }.should raise_error(Puppet::Error)
- end
+ it "should throw an exception if the file is not found" do
+ file = stub 'file', :path => @path, :name => @path
+ File.expects(:exist?).with(@path).returns(false)
- it "should fail intelligently if the file cannot be removed" do
- file = stub 'file', :path => @path, :name => @path
- File.expects(:exist?).with(@path).returns(true)
- File.expects(:unlink).with(@path).raises(ArgumentError)
+ proc { @searcher.destroy(file) }.should raise_error(Puppet::Error)
+ end
- proc { @searcher.destroy(file) }.should raise_error(Puppet::Error)
- end
+ it "should fail intelligently if the file cannot be removed" do
+ file = stub 'file', :path => @path, :name => @path
+ File.expects(:exist?).with(@path).returns(true)
+ File.expects(:unlink).with(@path).raises(ArgumentError)
- it "should use the path() method to calculate the path if it exists" do
- @searcher.meta_def(:path) do |name|
- name.upcase
+ proc { @searcher.destroy(file) }.should raise_error(Puppet::Error)
end
- file = stub 'file', :name => "/yay"
- File.expects(:exist?).with("/YAY").returns(true)
- File.expects(:unlink).with("/YAY")
+ it "should use the path() method to calculate the path if it exists" do
+ @searcher.meta_def(:path) do |name|
+ name.upcase
+ end
+
+ file = stub 'file', :name => "/yay"
+ File.expects(:exist?).with("/YAY").returns(true)
+ File.expects(:unlink).with("/YAY")
- @searcher.destroy(file)
+ @searcher.destroy(file)
+ end
end
-end
+end \ No newline at end of file