summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-14 20:13:44 -0600
committerLuke Kanies <luke@madstop.com>2008-02-14 20:13:44 -0600
commit6013b2500d9e799f8aba9f614de15d4eb477860a (patch)
tree6c134299d0e491cc46208a5122b8b8183f5bbd89 /spec/unit
parentaebd303e267a4b830592ffe3551bd80647802a20 (diff)
Refactoring the incremental checksum generation
slightly based on the code in type/file/checksum.rb.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/util/checksums.rb30
1 files changed, 12 insertions, 18 deletions
diff --git a/spec/unit/util/checksums.rb b/spec/unit/util/checksums.rb
index 50c213538..31cf24f5b 100755
--- a/spec/unit/util/checksums.rb
+++ b/spec/unit/util/checksums.rb
@@ -13,16 +13,6 @@ describe Puppet::Util::Checksums do
@summer.extend(Puppet::Util::Checksums)
end
- class LineYielder
- def initialize(content)
- @content = content
- end
-
- def each_line
- @content.split("\n").each { |line| yield line }
- end
- end
-
content_sums = [:md5, :md5lite, :sha1, :sha1lite]
file_only = [:timestamp, :mtime]
@@ -51,8 +41,10 @@ describe Puppet::Util::Checksums do
file = "/path/to/my/file"
- # Mocha doesn't seem to be able to mock multiple yields, yay.
- fh = LineYielder.new("firstline\nsecondline")
+ fh = mock 'filehandle'
+ fh.expects(:read).with(512).times(3).returns("firstline").then.returns("secondline").then.returns(nil)
+ #fh.expects(:read).with(512).returns("secondline")
+ #fh.expects(:read).with(512).returns(nil)
File.expects(:open).with(file, "r").yields(fh)
@@ -67,23 +59,25 @@ describe Puppet::Util::Checksums do
{:md5lite => Digest::MD5, :sha1lite => Digest::SHA1}.each do |sum, klass|
describe("when using %s" % sum) do
- it "should use #{klass} to calculate string checksums from the first 500 characters of the string" do
+ it "should use #{klass} to calculate string checksums from the first 512 characters of the string" do
content = "this is a test" * 100
- klass.expects(:hexdigest).with(content[0..499]).returns "whatever"
+ klass.expects(:hexdigest).with(content[0..511]).returns "whatever"
@summer.send(sum, content).should == "whatever"
end
- it "should use #{klass} to calculate a sum from the first 500 characters in the file" do
+ it "should use #{klass} to calculate a sum from the first 512 characters in the file" do
digest = mock 'digest'
+ klass.expects(:new).returns digest
file = "/path/to/my/file"
fh = mock 'filehandle'
- File.expects(:open).with(file, "r").yields(fh)
+ fh.expects(:read).with(512).returns('my content')
- fh.expects(:read).with(500).returns('my content')
+ File.expects(:open).with(file, "r").yields(fh)
- klass.expects(:hexdigest).with("my content").returns :mydigest
+ digest.expects(:<<).with "my content"
+ digest.expects(:hexdigest).returns :mydigest
@summer.send(sum.to_s + "_file", file).should == :mydigest
end