test/pgp_writer_test.rb in iostreams-0.19.0 vs test/pgp_writer_test.rb in iostreams-0.20.0

- old
+ new

@@ -23,11 +23,11 @@ it 'writes encrypted text file' do IOStreams::Pgp::Writer.open(file_name, recipient: 'receiver@example.org', binary: false) do |io| io.write(decrypted) end - result = IOStreams::Pgp::Reader.open(file_name, passphrase: 'receiver_passphrase', binary: false) { |file| file.read } + result = IOStreams::Pgp::Reader.open(file_name, passphrase: 'receiver_passphrase', binary: false, &:read) assert_equal decrypted, result end it 'writes encrypted binary file' do binary_file_name = File.join(File.dirname(__FILE__), 'files', 'spreadsheet.xlsx') @@ -37,20 +37,20 @@ IOStreams::Pgp::Writer.open(file_name, recipient: 'receiver@example.org') do |output| IOStreams.copy(input, output) end end - result = IOStreams::Pgp::Reader.open(file_name, passphrase: 'receiver_passphrase') { |file| file.read } + result = IOStreams::Pgp::Reader.open(file_name, passphrase: 'receiver_passphrase', &:read) assert_equal binary_data, result end it 'writes and signs encrypted file' do IOStreams::Pgp::Writer.open(file_name, recipient: 'receiver@example.org', signer: 'sender@example.org', signer_passphrase: 'sender_passphrase') do |io| io.write(decrypted) end - result = IOStreams::Pgp::Reader.open(file_name, passphrase: 'receiver_passphrase') { |file| file.read } + result = IOStreams::Pgp::Reader.open(file_name, passphrase: 'receiver_passphrase', &:read) assert_equal decrypted, result end it 'fails with bad signer passphrase' do skip 'GnuPG v2.1 and above passes when it should not' if IOStreams::Pgp.pgp_version.to_f >= 2.1 @@ -78,16 +78,19 @@ io.write(decrypted) end end end - it 'fails with stream output' do - string_io = StringIO.new - assert_raises NotImplementedError do - IOStreams::Pgp::Writer.open(string_io, recipient: 'receiver@example.org') do |io| - io.write(decrypted) - end + it 'writes to a stream' do + io_string = StringIO.new(''.b) + IOStreams::Pgp::Writer.open(io_string, recipient: 'receiver@example.org', signer: 'sender@example.org', signer_passphrase: 'sender_passphrase') do |io| + io.write(decrypted) end + + io = StringIO.new(io_string.string) + result = IOStreams::Pgp::Reader.open(io, passphrase: 'receiver_passphrase', &:read) + assert_equal decrypted, result end + end end end