Sha256: 4fe02673b2a2942e00677eb5de7d161895c2122a62eeb94aec5a8022005bf61b

Contents?: true

Size: 1.78 KB

Versions: 21

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'
require 'sugar-high/file'
require 'sugar-high/file_mutate'
File.mutate_ext :all

describe "SugarHigh::File" do
  let(:empty_file)      { fixture_file 'empty.txt' }
  let(:replace_file)    { fixture_file 'file.txt' }

  describe '#append with :content option' do    
    let(:append_file)    { fixture_file 'file.txt' }
  
    it 'should append content to existing file - class method' do      
      File.overwrite(append_file) do
        'Hello You'
      end
      File.append append_file, :content => 'Appended'
      content = File.read(append_file)
      content.should match /Hello You/
      content.should match /Appended/      
    end
  
    it 'should append content to existing file - instance method' do      
      File.overwrite(append_file) do
        'Hello You'
      end
      File.new(append_file).append :content => 'Appended'
      content = File.read(append_file)
      content.should match /Hello You/
      content.should match /Appended/      
    end
  end
  
  describe '#append with block' do    
    let(:append_file)    { fixture_file 'file.txt' }
  
    it "should append content to existing file using block arg - class method" do      
      File.overwrite(append_file) do
        'Hello You'
      end
      File.append append_file do
        'Appended'
      end
      content = File.read(replace_file)
      content.should match /Hello You/
      content.should match /Appended/      
    end
  
    it "should append content to existing file using block arg - instance method" do      
      File.overwrite(append_file) do
        'Hello You'
      end
      File.new(append_file).append do
        'Appended'
      end
      content = File.read(replace_file)
      content.should match /Hello You/
      content.should match /Appended/      
    end
  end  
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
sugar-high-0.5.5 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.5.4 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.5.3 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.5.1 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.5.0 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.9.5 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.9.3 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.9.2 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.9.1 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.9 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.8 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.7 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.6.4 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.6.3 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.6.2 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.6.1 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.6 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.5.2 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.5 spec/sugar-high/file_mutate/append_content_spec.rb
sugar-high-0.4.4.2 spec/sugar-high/file_mutate/append_content_spec.rb