Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert specs for OpenSSL::Digest to shared specs with Digest #1104

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions library/digest/sha512/length_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
require_relative 'shared/constants'
require_relative 'shared/length'

describe "Digest::SHA512#length" do
it_behaves_like :sha512_length, :length
it_behaves_like :sha512_length, :length, Digest::SHA512.new
end
9 changes: 5 additions & 4 deletions library/digest/sha512/shared/length.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require_relative 'constants'

describe :sha512_length, shared: true do
it "returns the length of the digest" do
cur_digest = Digest::SHA512.new
cur_digest.send(@method).should == SHA512Constants::BlankDigest.size
cur_digest << SHA512Constants::Contents
cur_digest.send(@method).should == SHA512Constants::Digest.size
@object.send(@method).should == SHA512Constants::BlankDigest.size
@object << SHA512Constants::Contents
@object.send(@method).should == SHA512Constants::Digest.size
end
end
3 changes: 1 addition & 2 deletions library/digest/sha512/size_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
require_relative 'shared/constants'
require_relative 'shared/length'

describe "Digest::SHA512#size" do
it_behaves_like :sha512_length, :size
it_behaves_like :sha512_length, :size, Digest::SHA512.new
end
10 changes: 3 additions & 7 deletions library/openssl/digest/digest_length_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative '../../../library/digest/sha1/shared/constants'
require_relative '../../../library/digest/sha256/shared/constants'
require_relative '../../../library/digest/sha384/shared/constants'
require_relative '../../../library/digest/sha512/shared/constants'
require_relative '../../digest/sha512/shared/length'
require 'openssl'

describe "OpenSSL::Digest#digest_length" do
Expand All @@ -19,9 +19,7 @@
OpenSSL::Digest.new('sha384').digest_length.should == SHA384Constants::DigestLength
end

it "returns a SHA512 digest length" do
OpenSSL::Digest.new('sha512').digest_length.should == SHA512Constants::DigestLength
end
it_behaves_like :sha512_length, :digest_length, OpenSSL::Digest.new('sha512')
end

context "when the digest object is created via a subclass" do
Expand All @@ -37,8 +35,6 @@
OpenSSL::Digest::SHA384.new.digest_length.should == SHA384Constants::DigestLength
end

it "returns a SHA512 digest length" do
OpenSSL::Digest::SHA512.new.digest_length.should == SHA512Constants::DigestLength
end
it_behaves_like :sha512_length, :digest_length, OpenSSL::Digest::SHA512.new
end
end