Sha256: 366aa9f194b48e7f46ff6e7e8e48079fe17a2477326b3d244e3f334f44da552b

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'
require 'fileutils'
require 'tmpdir'

describe FileSplicer do

  describe '.insert!' do

    let :before_insert do
      File.join spec_dir, 'data', 'splicer', 'before_insert'
    end

    let :abcd do
      File.join spec_dir, 'data', 'splicer', 'abcd'
    end

    let :after_insert do
      File.join spec_dir, 'data', 'splicer', 'after_insert'
    end

    it 'inserts one file into another' do
      Dir.mktmpdir do |tmp_dir|
        FileUtils.cp before_insert, tmp_dir
        test_file = File.join tmp_dir, 'before_insert'
        FileSplicer.insert! abcd, into: test_file, after: '3'
        test_file_contents = File.open(test_file).read
        after_insert_contents = File.open(after_insert).read
        test_file_contents.should == after_insert_contents
      end
    end
  end

  describe '#insert' do
    it 'inserts lines after a match' do
      original = ['0', '1', '2', '3']
      splicer = FileSplicer.new original
      result = splicer.insert ['a', 'b', 'c'], after: '2'
      result.should == ['0', '1', '2', 'a', 'b', 'c', '3']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reveal-ck-0.1.2 spec/lib/reveal-ck/file_splicer_spec.rb
reveal-ck-0.1.1 spec/lib/reveal-ck/file_splicer_spec.rb
reveal-ck-0.1.0 spec/lib/reveal-ck/file_splicer_spec.rb