summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-02-18 12:04:09 -0600
committerRick Bradley <rick@rickbradley.com>2008-02-18 12:04:09 -0600
commit516e5b62cbb5ed2fbbadcd211d3e843f0f049db8 (patch)
tree662161e3ac0de660ad92bd2b3391ace09672b26e /spec/unit
parentd260b7e762bf518f1f7c4ad99ba3c998b2c31c8d (diff)
downloadpuppet-516e5b62cbb5ed2fbbadcd211d3e843f0f049db8.tar.gz
puppet-516e5b62cbb5ed2fbbadcd211d3e843f0f049db8.tar.xz
puppet-516e5b62cbb5ed2fbbadcd211d3e843f0f049db8.zip
converting indirector checksum file specs from setup/teardown to before/after
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/checksum/file.rb176
1 files changed, 87 insertions, 89 deletions
diff --git a/spec/unit/indirector/checksum/file.rb b/spec/unit/indirector/checksum/file.rb
index 82319fa40..4f8ee98b2 100755
--- a/spec/unit/indirector/checksum/file.rb
+++ b/spec/unit/indirector/checksum/file.rb
@@ -7,22 +7,6 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/checksum/file'
-module FileChecksumTesting
- def setup
- Puppet.settings.stubs(:use)
- @store = Puppet::Checksum::File.new
-
- @value = "70924d6fa4b2d745185fa4660703a5c0"
- @sum = stub 'sum', :name => @value
-
- @dir = "/what/ever"
-
- Puppet.stubs(:[]).with(:bucketdir).returns(@dir)
-
- @path = @store.path(@value)
- end
-end
-
describe Puppet::Checksum::File do
it "should be a subclass of the File terminus class" do
Puppet::Checksum::File.superclass.should equal(Puppet::Indirector::File)
@@ -40,103 +24,117 @@ describe Puppet::Checksum::File, " when initializing" do
end
end
-describe Puppet::Checksum::File, " when determining file paths" do
- include FileChecksumTesting
- # I was previously passing the object in.
- it "should use the value passed in to path() as the checksum" do
- @value.expects(:name).never
- @store.path(@value)
- end
+describe Puppet::Checksum::File do
+ before :each do
+ Puppet.settings.stubs(:use)
+ @store = Puppet::Checksum::File.new
- it "should use the value of the :bucketdir setting as the root directory" do
- @path.should =~ %r{^#{@dir}}
- end
+ @value = "70924d6fa4b2d745185fa4660703a5c0"
+ @sum = stub 'sum', :name => @value
- it "should choose a path 8 directories deep with each directory name being the respective character in the checksum" do
- dirs = @value[0..7].split("").join(File::SEPARATOR)
- @path.should be_include(dirs)
- end
+ @dir = "/what/ever"
- it "should use the full checksum as the final directory name" do
- File.basename(File.dirname(@path)).should == @value
- end
+ Puppet.stubs(:[]).with(:bucketdir).returns(@dir)
- it "should use 'contents' as the actual file name" do
- File.basename(@path).should == "contents"
+ @path = @store.path(@value)
end
- it "should use the bucketdir, the 8 sum character directories, the full checksum, and 'contents' as the full file name" do
- @path.should == [@dir, @value[0..7].split(""), @value, "contents"].flatten.join(File::SEPARATOR)
- end
-end
-describe Puppet::Checksum::File, " when retrieving files" do
- include FileChecksumTesting
+ describe Puppet::Checksum::File, " when determining file paths" do
- # The smallest test that will use the calculated path
- it "should look for the calculated path" do
- File.expects(:exist?).with(@path).returns(false)
- @store.find(@value)
- end
+ # I was previously passing the object in.
+ it "should use the value passed in to path() as the checksum" do
+ @value.expects(:name).never
+ @store.path(@value)
+ end
- it "should return an instance of Puppet::Checksum created with the content if the file exists" do
- content = "my content"
- sum = stub 'file'
- Puppet::Checksum.expects(:new).with(content).returns(sum)
+ it "should use the value of the :bucketdir setting as the root directory" do
+ @path.should =~ %r{^#{@dir}}
+ end
- File.expects(:exist?).with(@path).returns(true)
- File.expects(:read).with(@path).returns(content)
+ it "should choose a path 8 directories deep with each directory name being the respective character in the checksum" do
+ dirs = @value[0..7].split("").join(File::SEPARATOR)
+ @path.should be_include(dirs)
+ end
- @store.find(@value).should equal(sum)
- end
+ it "should use the full checksum as the final directory name" do
+ File.basename(File.dirname(@path)).should == @value
+ end
- it "should return nil if no file is found" do
- File.expects(:exist?).with(@path).returns(false)
- @store.find(@value).should be_nil
- end
+ it "should use 'contents' as the actual file name" do
+ File.basename(@path).should == "contents"
+ 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 { @store.find(@value) }.should raise_error(Puppet::Error)
+ it "should use the bucketdir, the 8 sum character directories, the full checksum, and 'contents' as the full file name" do
+ @path.should == [@dir, @value[0..7].split(""), @value, "contents"].flatten.join(File::SEPARATOR)
+ end
end
-end
-describe Puppet::Checksum::File, " when saving files" do
- include FileChecksumTesting
+ describe Puppet::Checksum::File, " when retrieving files" do
+
+ # The smallest test that will use the calculated path
+ it "should look for the calculated path" do
+ File.expects(:exist?).with(@path).returns(false)
+ @store.find(@value)
+ end
+
+ it "should return an instance of Puppet::Checksum created with the content if the file exists" do
+ content = "my content"
+ sum = stub 'file'
+ Puppet::Checksum.expects(:new).with(content).returns(sum)
+
+ File.expects(:exist?).with(@path).returns(true)
+ File.expects(:read).with(@path).returns(content)
- # LAK:FIXME I don't know how to include in the spec the fact that we're
- # using the superclass's save() method and thus are acquiring all of
- # it's behaviours.
- it "should save the content to the calculated path" do
- File.stubs(:directory?).with(File.dirname(@path)).returns(true)
- File.expects(:open).with(@path, "w")
+ @store.find(@value).should equal(sum)
+ end
- file = stub 'file', :name => @value
- @store.save(file)
+ it "should return nil if no file is found" do
+ File.expects(:exist?).with(@path).returns(false)
+ @store.find(@value).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 { @store.find(@value) }.should raise_error(Puppet::Error)
+ end
end
- it "should make any directories necessary for storage" do
- FileUtils.expects(:mkdir_p).with do |arg|
- File.umask == 0007 and arg == File.dirname(@path)
+ describe Puppet::Checksum::File, " when saving files" do
+
+ # LAK:FIXME I don't know how to include in the spec the fact that we're
+ # using the superclass's save() method and thus are acquiring all of
+ # it's behaviours.
+ it "should save the content to the calculated path" do
+ File.stubs(:directory?).with(File.dirname(@path)).returns(true)
+ File.expects(:open).with(@path, "w")
+
+ file = stub 'file', :name => @value
+ @store.save(file)
end
- File.expects(:directory?).with(File.dirname(@path)).returns(true)
- File.expects(:open).with(@path, "w")
- file = stub 'file', :name => @value
- @store.save(file)
+ it "should make any directories necessary for storage" do
+ FileUtils.expects(:mkdir_p).with do |arg|
+ File.umask == 0007 and arg == File.dirname(@path)
+ end
+ File.expects(:directory?).with(File.dirname(@path)).returns(true)
+ File.expects(:open).with(@path, "w")
+
+ file = stub 'file', :name => @value
+ @store.save(file)
+ end
end
-end
-describe Puppet::Checksum::File, " when deleting files" do
- include FileChecksumTesting
+ describe Puppet::Checksum::File, " when deleting files" do
- it "should remove the file at the calculated path" do
- File.expects(:exist?).with(@path).returns(true)
- File.expects(:unlink).with(@path)
+ it "should remove the file at the calculated path" do
+ File.expects(:exist?).with(@path).returns(true)
+ File.expects(:unlink).with(@path)
- file = stub 'file', :name => @value
- @store.destroy(file)
+ file = stub 'file', :name => @value
+ @store.destroy(file)
+ end
end
-end
+end \ No newline at end of file