|
5 | 5 | require_relative '../../../library/digest/sha512/shared/constants' |
6 | 6 | require 'openssl' |
7 | 7 |
|
8 | | -describe "OpenSSL::Digest initialization" do |
| 8 | +describe "OpenSSL::Digest#initialize" do |
9 | 9 | describe "can be called with a digest name" do |
10 | 10 | it "returns a SHA1 object" do |
11 | 11 | OpenSSL::Digest.new("sha1").name.should == "SHA1" |
|
31 | 31 | -> { OpenSSL::Digest.new(:SHA1) }.should raise_error(TypeError, /wrong argument type Symbol/) |
32 | 32 | end |
33 | 33 |
|
34 | | - it "doest not call #to_str on the argument" do |
| 34 | + it "does not call #to_str on the argument" do |
35 | 35 | name = mock("digest name") |
36 | 36 | name.should_not_receive(:to_str) |
37 | 37 | -> { OpenSSL::Digest.new(name) }.should raise_error(TypeError, /wrong argument type/) |
|
55 | 55 | OpenSSL::Digest.new(OpenSSL::Digest::SHA512.new).name.should == "SHA512" |
56 | 56 | end |
57 | 57 |
|
58 | | - it "cannot be called with a digest class" do |
59 | | - -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError, /wrong argument type Class/) |
60 | | - end |
61 | | - |
62 | | - it "ignores the state of the name object" do |
| 58 | + it "ignores the state of the digest object" do |
63 | 59 | sha1 = OpenSSL::Digest.new('sha1', SHA1Constants::Contents) |
64 | 60 | OpenSSL::Digest.new(sha1).digest.should == SHA1Constants::BlankDigest |
65 | 61 | end |
66 | 62 | end |
67 | 63 |
|
68 | | - describe "ititialization with an empty string" do |
| 64 | + it "cannot be called with a digest class" do |
| 65 | + -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError, /wrong argument type Class/) |
| 66 | + end |
| 67 | + |
| 68 | + context "when called without an initial String argument" do |
69 | 69 | it "returns a SHA1 digest" do |
70 | 70 | OpenSSL::Digest.new("sha1").digest.should == SHA1Constants::BlankDigest |
71 | 71 | end |
|
83 | 83 | end |
84 | 84 | end |
85 | 85 |
|
86 | | - describe "can be called with a digest name and data" do |
87 | | - it "returns a SHA1 digest" do |
| 86 | + context "when called with an initial String argument" do |
| 87 | + it "returns a SHA1 digest of that argument" do |
88 | 88 | OpenSSL::Digest.new("sha1", SHA1Constants::Contents).digest.should == SHA1Constants::Digest |
89 | 89 | end |
90 | 90 |
|
91 | | - it "returns a SHA256 digest" do |
| 91 | + it "returns a SHA256 digest of that argument" do |
92 | 92 | OpenSSL::Digest.new("sha256", SHA256Constants::Contents).digest.should == SHA256Constants::Digest |
93 | 93 | end |
94 | 94 |
|
95 | | - it "returns a SHA384 digest" do |
| 95 | + it "returns a SHA384 digest of that argument" do |
96 | 96 | OpenSSL::Digest.new("sha384", SHA384Constants::Contents).digest.should == SHA384Constants::Digest |
97 | 97 | end |
98 | 98 |
|
99 | | - it "returns a SHA512 digest" do |
| 99 | + it "returns a SHA512 digest of that argument" do |
100 | 100 | OpenSSL::Digest.new("sha512", SHA512Constants::Contents).digest.should == SHA512Constants::Digest |
101 | 101 | end |
102 | 102 | end |
103 | 103 |
|
104 | 104 | context "can be called on subclasses" do |
105 | | - describe "can be called without data on subclasses" do |
| 105 | + describe "can be called without an initial String argument on subclasses" do |
106 | 106 | it "returns a SHA1 digest" do |
107 | 107 | OpenSSL::Digest::SHA1.new.digest.should == SHA1Constants::BlankDigest |
108 | 108 | end |
|
120 | 120 | end |
121 | 121 | end |
122 | 122 |
|
123 | | - describe "can be called with data on subclasses" do |
| 123 | + describe "can be called with an initial String argument on subclasses" do |
124 | 124 | it "returns a SHA1 digest" do |
125 | 125 | OpenSSL::Digest::SHA1.new(SHA1Constants::Contents).digest.should == SHA1Constants::Digest |
126 | 126 | end |
|
0 commit comments