summaryrefslogtreecommitdiff
path: root/spec/ruby/library/digest/md5
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/digest/md5')
-rw-r--r--spec/ruby/library/digest/md5/append_spec.rb7
-rw-r--r--spec/ruby/library/digest/md5/block_length_spec.rb12
-rw-r--r--spec/ruby/library/digest/md5/digest_bang_spec.rb13
-rw-r--r--spec/ruby/library/digest/md5/digest_length_spec.rb12
-rw-r--r--spec/ruby/library/digest/md5/digest_spec.rb32
-rw-r--r--spec/ruby/library/digest/md5/equal_spec.rb38
-rw-r--r--spec/ruby/library/digest/md5/file_spec.rb43
-rw-r--r--spec/ruby/library/digest/md5/hexdigest_bang_spec.rb14
-rw-r--r--spec/ruby/library/digest/md5/hexdigest_spec.rb32
-rw-r--r--spec/ruby/library/digest/md5/inspect_spec.rb12
-rw-r--r--spec/ruby/library/digest/md5/length_spec.rb8
-rw-r--r--spec/ruby/library/digest/md5/reset_spec.rb15
-rw-r--r--spec/ruby/library/digest/md5/shared/constants.rb16
-rw-r--r--spec/ruby/library/digest/md5/shared/length.rb8
-rw-r--r--spec/ruby/library/digest/md5/shared/sample.rb17
-rw-r--r--spec/ruby/library/digest/md5/shared/update.rb7
-rw-r--r--spec/ruby/library/digest/md5/size_spec.rb8
-rw-r--r--spec/ruby/library/digest/md5/to_s_spec.rb24
-rw-r--r--spec/ruby/library/digest/md5/update_spec.rb7
19 files changed, 325 insertions, 0 deletions
diff --git a/spec/ruby/library/digest/md5/append_spec.rb b/spec/ruby/library/digest/md5/append_spec.rb
new file mode 100644
index 0000000000..ad828c83c1
--- /dev/null
+++ b/spec/ruby/library/digest/md5/append_spec.rb
@@ -0,0 +1,7 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../shared/update', __FILE__)
+
+describe "Digest::MD5#<<" do
+ it_behaves_like(:md5_update, :<<)
+end
diff --git a/spec/ruby/library/digest/md5/block_length_spec.rb b/spec/ruby/library/digest/md5/block_length_spec.rb
new file mode 100644
index 0000000000..acc3108da4
--- /dev/null
+++ b/spec/ruby/library/digest/md5/block_length_spec.rb
@@ -0,0 +1,12 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#block_length" do
+
+ it "returns the length of digest block" do
+ cur_digest = Digest::MD5.new
+ cur_digest.block_length.should == MD5Constants::BlockLength
+ end
+
+end
+
diff --git a/spec/ruby/library/digest/md5/digest_bang_spec.rb b/spec/ruby/library/digest/md5/digest_bang_spec.rb
new file mode 100644
index 0000000000..88b865dcba
--- /dev/null
+++ b/spec/ruby/library/digest/md5/digest_bang_spec.rb
@@ -0,0 +1,13 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#digest!" do
+
+ it "returns a digest and can digest!" do
+ cur_digest = Digest::MD5.new
+ cur_digest << MD5Constants::Contents
+ cur_digest.digest!().should == MD5Constants::Digest
+ cur_digest.digest().should == MD5Constants::BlankDigest
+ end
+
+end
diff --git a/spec/ruby/library/digest/md5/digest_length_spec.rb b/spec/ruby/library/digest/md5/digest_length_spec.rb
new file mode 100644
index 0000000000..426e42af76
--- /dev/null
+++ b/spec/ruby/library/digest/md5/digest_length_spec.rb
@@ -0,0 +1,12 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#digest_length" do
+
+ it "returns the length of computed digests" do
+ cur_digest = Digest::MD5.new
+ cur_digest.digest_length.should == MD5Constants::DigestLength
+ end
+
+end
+
diff --git a/spec/ruby/library/digest/md5/digest_spec.rb b/spec/ruby/library/digest/md5/digest_spec.rb
new file mode 100644
index 0000000000..1568c630aa
--- /dev/null
+++ b/spec/ruby/library/digest/md5/digest_spec.rb
@@ -0,0 +1,32 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#digest" do
+
+ it "returns a digest" do
+ cur_digest = Digest::MD5.new
+ cur_digest.digest().should == MD5Constants::BlankDigest
+
+ # add something to check that the state is reset later
+ cur_digest << "test"
+
+ cur_digest.digest(MD5Constants::Contents).should == MD5Constants::Digest
+ # second invocation is intentional, to make sure there are no side-effects
+ cur_digest.digest(MD5Constants::Contents).should == MD5Constants::Digest
+
+ # after all is done, verify that the digest is in the original, blank state
+ cur_digest.digest.should == MD5Constants::BlankDigest
+ end
+
+end
+
+describe "Digest::MD5.digest" do
+
+ it "returns a digest" do
+ Digest::MD5.digest(MD5Constants::Contents).should == MD5Constants::Digest
+ # second invocation is intentional, to make sure there are no side-effects
+ Digest::MD5.digest(MD5Constants::Contents).should == MD5Constants::Digest
+ Digest::MD5.digest("").should == MD5Constants::BlankDigest
+ end
+
+end
diff --git a/spec/ruby/library/digest/md5/equal_spec.rb b/spec/ruby/library/digest/md5/equal_spec.rb
new file mode 100644
index 0000000000..0b776f53c0
--- /dev/null
+++ b/spec/ruby/library/digest/md5/equal_spec.rb
@@ -0,0 +1,38 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#==" do
+
+ it "equals itself" do
+ cur_digest = Digest::MD5.new
+ cur_digest.should == cur_digest
+ end
+
+ it "equals the string representing its hexdigest" do
+ cur_digest = Digest::MD5.new
+ cur_digest.should == MD5Constants::BlankHexdigest
+ end
+
+ it "equals the appropriate object that responds to to_str" do
+ # blank digest
+ cur_digest = Digest::MD5.new
+ obj = mock(MD5Constants::BlankHexdigest)
+ obj.should_receive(:to_str).and_return(MD5Constants::BlankHexdigest)
+ cur_digest.should == obj
+
+ # non-blank digest
+ cur_digest = Digest::MD5.new
+ cur_digest << "test"
+ d_value = cur_digest.hexdigest
+ (obj = mock(d_value)).should_receive(:to_str).and_return(d_value)
+ cur_digest.should == obj
+ end
+
+ it "equals the same digest for a different object" do
+ cur_digest = Digest::MD5.new
+ cur_digest2 = Digest::MD5.new
+ cur_digest.should == cur_digest2
+ end
+
+end
+
diff --git a/spec/ruby/library/digest/md5/file_spec.rb b/spec/ruby/library/digest/md5/file_spec.rb
new file mode 100644
index 0000000000..c7f4328546
--- /dev/null
+++ b/spec/ruby/library/digest/md5/file_spec.rb
@@ -0,0 +1,43 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../../../../core/file/shared/read', __FILE__)
+
+describe "Digest::MD5.file" do
+
+ describe "when passed a path to a file that exists" do
+ before :each do
+ @file = tmp("md5_temp")
+ touch(@file, 'wb') {|f| f.write MD5Constants::Contents }
+ end
+
+ after :each do
+ rm_r @file
+ end
+
+ it "returns a Digest::MD5 object" do
+ Digest::MD5.file(@file).should be_kind_of(Digest::MD5)
+ end
+
+ it "returns a Digest::MD5 object with the correct digest" do
+ Digest::MD5.file(@file).digest.should == MD5Constants::Digest
+ end
+
+ it "calls #to_str on an object and returns the Digest::MD5 with the result" do
+ obj = mock("to_str")
+ obj.should_receive(:to_str).and_return(@file)
+ result = Digest::MD5.file(obj)
+ result.should be_kind_of(Digest::MD5)
+ result.digest.should == MD5Constants::Digest
+ end
+ end
+
+ it_behaves_like :file_read_directory, :file, Digest::MD5
+
+ it "raises a Errno::ENOENT when passed a path that does not exist" do
+ lambda { Digest::MD5.file("") }.should raise_error(Errno::ENOENT)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { Digest::MD5.file(nil) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/digest/md5/hexdigest_bang_spec.rb b/spec/ruby/library/digest/md5/hexdigest_bang_spec.rb
new file mode 100644
index 0000000000..fe67136c97
--- /dev/null
+++ b/spec/ruby/library/digest/md5/hexdigest_bang_spec.rb
@@ -0,0 +1,14 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#hexdigest!" do
+
+ it "returns a hexdigest and resets the state" do
+ cur_digest = Digest::MD5.new
+
+ cur_digest << MD5Constants::Contents
+ cur_digest.hexdigest!.should == MD5Constants::Hexdigest
+ cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
+ end
+
+end
diff --git a/spec/ruby/library/digest/md5/hexdigest_spec.rb b/spec/ruby/library/digest/md5/hexdigest_spec.rb
new file mode 100644
index 0000000000..9caec29f38
--- /dev/null
+++ b/spec/ruby/library/digest/md5/hexdigest_spec.rb
@@ -0,0 +1,32 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#hexdigest" do
+
+ it "returns a hexdigest" do
+ cur_digest = Digest::MD5.new
+ cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
+
+ # add something to check that the state is reset later
+ cur_digest << "test"
+
+ cur_digest.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
+ # second invocation is intentional, to make sure there are no side-effects
+ cur_digest.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
+
+ # after all is done, verify that the digest is in the original, blank state
+ cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
+ end
+
+end
+
+describe "Digest::MD5.hexdigest" do
+
+ it "returns a hexdigest" do
+ Digest::MD5.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
+ # second invocation is intentional, to make sure there are no side-effects
+ Digest::MD5.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
+ Digest::MD5.hexdigest("").should == MD5Constants::BlankHexdigest
+ end
+
+end
diff --git a/spec/ruby/library/digest/md5/inspect_spec.rb b/spec/ruby/library/digest/md5/inspect_spec.rb
new file mode 100644
index 0000000000..e23465337a
--- /dev/null
+++ b/spec/ruby/library/digest/md5/inspect_spec.rb
@@ -0,0 +1,12 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#inspect" do
+
+ it "returns a Ruby object representation" do
+ cur_digest = Digest::MD5.new
+ cur_digest.inspect.should == "#<#{MD5Constants::Klass}: #{cur_digest.hexdigest()}>"
+ end
+
+end
+
diff --git a/spec/ruby/library/digest/md5/length_spec.rb b/spec/ruby/library/digest/md5/length_spec.rb
new file mode 100644
index 0000000000..13eaf2e8d5
--- /dev/null
+++ b/spec/ruby/library/digest/md5/length_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
+
+describe "Digest::MD5#length" do
+ it_behaves_like :md5_length, :length
+end
+
diff --git a/spec/ruby/library/digest/md5/reset_spec.rb b/spec/ruby/library/digest/md5/reset_spec.rb
new file mode 100644
index 0000000000..d95ecfaf8c
--- /dev/null
+++ b/spec/ruby/library/digest/md5/reset_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#reset" do
+
+ it "returns digest state to initial conditions" do
+ cur_digest = Digest::MD5.new
+ cur_digest.update MD5Constants::Contents
+ cur_digest.digest().should_not == MD5Constants::BlankDigest
+ cur_digest.reset
+ cur_digest.digest().should == MD5Constants::BlankDigest
+ end
+
+end
+
diff --git a/spec/ruby/library/digest/md5/shared/constants.rb b/spec/ruby/library/digest/md5/shared/constants.rb
new file mode 100644
index 0000000000..fdfae56d63
--- /dev/null
+++ b/spec/ruby/library/digest/md5/shared/constants.rb
@@ -0,0 +1,16 @@
+# -*- encoding: binary -*-
+require 'digest/md5'
+
+module MD5Constants
+
+ Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
+
+ Klass = ::Digest::MD5
+ BlockLength = 64
+ DigestLength = 16
+ BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
+ Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
+ BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
+ Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
+
+end
diff --git a/spec/ruby/library/digest/md5/shared/length.rb b/spec/ruby/library/digest/md5/shared/length.rb
new file mode 100644
index 0000000000..c5b2b97b58
--- /dev/null
+++ b/spec/ruby/library/digest/md5/shared/length.rb
@@ -0,0 +1,8 @@
+describe :md5_length, shared: true do
+ it "returns the length of the digest" do
+ cur_digest = Digest::MD5.new
+ cur_digest.send(@method).should == MD5Constants::BlankDigest.size
+ cur_digest << MD5Constants::Contents
+ cur_digest.send(@method).should == MD5Constants::Digest.size
+ end
+end
diff --git a/spec/ruby/library/digest/md5/shared/sample.rb b/spec/ruby/library/digest/md5/shared/sample.rb
new file mode 100644
index 0000000000..2bb4f658b1
--- /dev/null
+++ b/spec/ruby/library/digest/md5/shared/sample.rb
@@ -0,0 +1,17 @@
+# -*- encoding: binary -*-
+
+require 'digest/md5'
+
+module MD5Constants
+
+ Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
+
+ Klass = ::Digest::MD5
+ BlockLength = 64
+ DigestLength = 16
+ BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
+ Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
+ BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
+ Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
+
+end
diff --git a/spec/ruby/library/digest/md5/shared/update.rb b/spec/ruby/library/digest/md5/shared/update.rb
new file mode 100644
index 0000000000..be8622aed5
--- /dev/null
+++ b/spec/ruby/library/digest/md5/shared/update.rb
@@ -0,0 +1,7 @@
+describe :md5_update, shared: true do
+ it "can update" do
+ cur_digest = Digest::MD5.new
+ cur_digest.send @method, MD5Constants::Contents
+ cur_digest.digest.should == MD5Constants::Digest
+ end
+end
diff --git a/spec/ruby/library/digest/md5/size_spec.rb b/spec/ruby/library/digest/md5/size_spec.rb
new file mode 100644
index 0000000000..311286e679
--- /dev/null
+++ b/spec/ruby/library/digest/md5/size_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
+
+describe "Digest::MD5#size" do
+ it_behaves_like :md5_length, :size
+end
+
diff --git a/spec/ruby/library/digest/md5/to_s_spec.rb b/spec/ruby/library/digest/md5/to_s_spec.rb
new file mode 100644
index 0000000000..59c17ec821
--- /dev/null
+++ b/spec/ruby/library/digest/md5/to_s_spec.rb
@@ -0,0 +1,24 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+require 'digest/md5'
+
+require File.expand_path('../shared/constants', __FILE__)
+
+describe "Digest::MD5#to_s" do
+
+ it "returns a hexdigest" do
+ cur_digest = Digest::MD5.new
+ cur_digest.to_s.should == MD5Constants::BlankHexdigest
+ end
+
+ it "does not change the internal state" do
+ cur_digest = Digest::MD5.new
+ cur_digest.to_s.should == MD5Constants::BlankHexdigest
+ cur_digest.to_s.should == MD5Constants::BlankHexdigest
+
+ cur_digest << MD5Constants::Contents
+ cur_digest.to_s.should == MD5Constants::Hexdigest
+ cur_digest.to_s.should == MD5Constants::Hexdigest
+ end
+
+end
diff --git a/spec/ruby/library/digest/md5/update_spec.rb b/spec/ruby/library/digest/md5/update_spec.rb
new file mode 100644
index 0000000000..5a271481f7
--- /dev/null
+++ b/spec/ruby/library/digest/md5/update_spec.rb
@@ -0,0 +1,7 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../shared/update', __FILE__)
+
+describe "Digest::MD5#update" do
+ it_behaves_like :md5_update, :update
+end