Sha256: 3008eb02f2e9f6d06bc4fb47dddbed6a60203325234b22b1d5318531d2f7a029

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'
File.file_mutate :insert_content

describe FileMutate do
  let(:empty_file)      { fixture_file 'empty.txt' }
  let(:class_file)      { fixture_file 'class_file.rb'}
  let(:routes_file)     { fixture_file 'routes_file.rb' }
  let(:app_file)        { fixture_file 'application_file.rb' }

  describe '#insert_into' do
    let(:insertion_file)    { fixture_file 'insertion.txt' }
    before :each do
      File.overwrite(insertion_file) do
        'Goodbye'
      end
    end

    after :each do
      File.delete insertion_file if File.file?(insertion_file)
    end


    describe '#insert before last' do
      context ':content option and :before_last option' do
        it "should insert Hello before last end statement" do
          File.insert_into class_file, :content => '  # Hello', :before_last => 'end' 
          puts File.read(class_file)
          File.read(class_file).should match /end\s+# Hello\s+end/
          File.remove_content_from class_file, :content => '  # Hello'
        end
      end

      context ':content option and :before_last option and repeat=true' do
        it "should insert Hello before last end statement but don't repeat" do
          File.insert_into class_file, :content => '  # Hello', :before_last => 'end', :no_repeat => true
          puts File.read(class_file)
          File.read(class_file).should match /end\s+# Hello\s+end/
          File.remove_content_from class_file, :content => '  # Hello'
        end
      end

      context 'block content and :before_last' do
        it "should insert Hello before last end statement" do
          File.insert_into class_file, :before_last => 'end' do
            '  # Hello'
          end
          puts File.read(class_file)
          File.read(class_file).should match /end\s+# Hello\s+end/
          File.remove_content_from class_file, :content => '  # Hello'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
file_mutate-0.1.3 spec/file_mutate/insert_before_last_spec.rb
file_mutate-0.1.2 spec/file_mutate/insert_before_last_spec.rb