Sha256: 9ee24f5f7ba1da40a5396254ca6b1039c427fc0dcb1611a252a16a6d42550601

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

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

module RevealCK
  describe FileSlicer do

    describe '.remove!' do

      let :before_remove do
        File.join spec_dir, 'data', 'slicer', 'before_remove'
      end

      let :after_remove do
        File.join spec_dir, 'data', 'slicer', 'after_remove'
      end

      it 'removes a range of lines from a file' do
        Dir.mktmpdir do |tmp_dir|
          FileUtils.cp before_remove, tmp_dir
          test_file = File.join tmp_dir, 'before_remove'
          FileSlicer.remove! test_file, 3..6
          test_file_contents = File.open(test_file).read
          after_remove_contents = File.open(after_remove).read
          test_file_contents.should == after_remove_contents
        end
      end
    end

    describe '#remove' do

      it 'returns lines with the range removed' do
        lines = [
                 'a',
                 'b',
                 'c',
                 'd'
                ]
        slicer = FileSlicer.new lines
        slicer.remove(1..2).should == ['a', 'd']
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reveal-ck-0.1.6 spec/lib/reveal-ck/file_slicer_spec.rb
reveal-ck-0.1.5 spec/lib/reveal-ck/file_slicer_spec.rb
reveal-ck-0.1.4 spec/lib/reveal-ck/file_slicer_spec.rb
reveal-ck-0.1.3 spec/lib/reveal-ck/file_slicer_spec.rb