Sha256: 31d8d92c77f5eba4250afacd2c1d4de2a78ff34effcd3c7375feab284a52d591

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

require 'test_helper'

class TestFile < Minitest::Test
  def setup
    File.open 'file', 'w' do |f|
      f.puts '1'
      f.puts '2'
      f.puts '3'
    end
  end

  def teardown
    FileUtils.rm 'file'

    if File.exist? 'copy'
      FileUtils.rm 'copy'
    end
  end

  def test_copylines
    File.copylines 'file', 'copy' do |line|
      /1/ === line ? "First line\n": line
    end

    assert_equal "First line\n2\n3\n", File.read('copy')
  end

  def test_copylines_on_the_same_file
    File.copylines 'file', 'file' do |line|
      /1/ === line ? "First line\n": line
    end

    assert_equal "First line\n2\n3\n", File.read('file')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
subshift-0.0.1.pre test/test_file.rb