test/pgp_reader_test.rb in iostreams-0.14.0 vs test/pgp_reader_test.rb in iostreams-0.15.0

- old
+ new

@@ -1,44 +1,44 @@ require_relative 'test_helper' -module Streams - class PgpReaderTest < Minitest::Test - describe IOStreams::Pgp::Reader do - before do - file_name = File.join(File.dirname(__FILE__), 'files', 'text.txt') - @data = File.read(file_name) - @temp_file = Tempfile.new('iostreams') - @file_name = @temp_file.to_path - end +class PgpReaderTest < Minitest::Test + describe IOStreams::Pgp::Reader do + let :temp_file do + Tempfile.new('iostreams') + end - after do - @temp_file.delete if @temp_file - end + let :decrypted do + file_name = File.join(File.dirname(__FILE__), 'files', 'text.txt') + File.read(file_name) + end - describe '.open' do - it 'reads encrypted file' do - IOStreams::Pgp::Writer.open(@file_name, recipient: 'receiver@example.org') do |io| - io.write(@data) - end + after do + temp_file.delete + end - result = IOStreams::Pgp::Reader.open(@file_name, passphrase: 'receiver_passphrase') { |file| file.read } - assert_equal @data, result + describe '.open' do + it 'reads encrypted file' do + IOStreams::Pgp::Writer.open(temp_file.path, recipient: 'receiver@example.org') do |io| + io.write(decrypted) end - it 'fails with bad passphrase' do - assert_raises IOStreams::Pgp::Failure do - IOStreams::Pgp::Reader.open(@file_name, passphrase: 'BAD') { |file| file.read } - end - end + result = IOStreams::Pgp::Reader.open(temp_file.path, passphrase: 'receiver_passphrase') { |file| file.read } + assert_equal decrypted, result + end - it 'fails with stream input' do - io = StringIO.new - assert_raises NotImplementedError do - IOStreams::Pgp::Reader.open(io, passphrase: 'BAD') { |file| file.read } - end + it 'fails with bad passphrase' do + assert_raises IOStreams::Pgp::Failure do + IOStreams::Pgp::Reader.open(temp_file.path, passphrase: 'BAD') { |file| file.read } end + end + it 'fails with stream input' do + io = StringIO.new + assert_raises NotImplementedError do + IOStreams::Pgp::Reader.open(io, passphrase: 'BAD') { |file| file.read } + end end end + end end