From f234d51eaba861edea925eabb564a0bee41b96a0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 28 Mar 2020 00:22:51 +0100 Subject: Update to ruby/spec@ec84479 --- spec/ruby/library/digest/sha2/hexdigest_spec.rb | 32 +++++++++++++++++++++++++ spec/ruby/library/digest/sha256/file_spec.rb | 4 ++++ 2 files changed, 36 insertions(+) create mode 100644 spec/ruby/library/digest/sha2/hexdigest_spec.rb (limited to 'spec/ruby/library/digest') diff --git a/spec/ruby/library/digest/sha2/hexdigest_spec.rb b/spec/ruby/library/digest/sha2/hexdigest_spec.rb new file mode 100644 index 0000000000..79beca5788 --- /dev/null +++ b/spec/ruby/library/digest/sha2/hexdigest_spec.rb @@ -0,0 +1,32 @@ +require_relative '../../../spec_helper' +require_relative '../sha256/shared/constants' + +describe "Digest::SHA2#hexdigest" do + + it "returns a SHA256 hexdigest by default" do + cur_digest = Digest::SHA2.new + cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest + + # add something to check that the state is reset later + cur_digest << "test" + + cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest + # second invocation is intentional, to make sure there are no side-effects + cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest + + # after all is done, verify that the digest is in the original, blank state + cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest + end + +end + +describe "Digest::SHA2.hexdigest" do + + it "returns a SHA256 hexdigest by default" do + Digest::SHA2.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest + # second invocation is intentional, to make sure there are no side-effects + Digest::SHA2.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest + Digest::SHA2.hexdigest("").should == SHA256Constants::BlankHexdigest + end + +end diff --git a/spec/ruby/library/digest/sha256/file_spec.rb b/spec/ruby/library/digest/sha256/file_spec.rb index 6103971b5a..8cbc5a2755 100644 --- a/spec/ruby/library/digest/sha256/file_spec.rb +++ b/spec/ruby/library/digest/sha256/file_spec.rb @@ -22,6 +22,10 @@ describe "Digest::SHA256.file" do Digest::SHA256.file(@file).digest.should == SHA256Constants::Digest end + it "can be used with frozen-string-literal" do + ruby_exe("require 'digest'; puts Digest::SHA256.file(#{@file.inspect}).digest.inspect", options: "--enable=frozen-string-literal").chomp.should == SHA256Constants::Digest.inspect + end + it "calls #to_str on an object and returns the Digest::SHA256 with the result" do obj = mock("to_str") obj.should_receive(:to_str).and_return(@file) -- cgit v1.2.3