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

- old
+ new

@@ -1,34 +1,35 @@ require_relative 'test_helper' -# Unit Test for IOStreams::File -module Streams - class FileWriterTest < Minitest::Test - describe IOStreams::File::Writer do - before do - @file_name = File.join(File.dirname(__FILE__), 'files', 'text.txt') - @data = File.read(@file_name) - end +class FileWriterTest < Minitest::Test + describe IOStreams::File::Writer do + let :file_name do + File.join(File.dirname(__FILE__), 'files', 'text.txt') + end - describe '.open' do - it 'file' do - temp_file = Tempfile.new('rocket_job') - file_name = temp_file.to_path - IOStreams::File::Writer.open(file_name) do |io| - io.write(@data) - end - result = File.read(file_name) - assert_equal @data, result + let :raw do + File.read(file_name) + end + + describe '.open' do + it 'file' do + temp_file = Tempfile.new('rocket_job') + file_name = temp_file.to_path + IOStreams::File::Writer.open(file_name) do |io| + io.write(raw) end + result = File.read(file_name) + assert_equal raw, result + end - it 'stream' do - io_string = StringIO.new + it 'does not support streams' do + io_string = StringIO.new + assert_raises ArgumentError do IOStreams::File::Writer.open(io_string) do |io| - io.write(@data) + io.write(raw) end - assert_equal @data, io_string.string end end - end + end end