Sha256: e707074cde81b0c9871f8cdd3863fde6240322c12acb39f340ed0babd5b20ec7

Contents?: true

Size: 1.76 KB

Versions: 31

Compression:

Stored size: 1.76 KB

Contents

require 'test_helper'

include Beet::FileSystem

# define some methods that file_system recipes expect to exist
def root; '.'; end
class FileSystemTest < Test::Unit::TestCase
  context "#add_after" do
    setup do
      @filename = 'test.file'
      File.open(@filename,'w') do |f|
        f.puts "first line"
        f.puts "second line"
      end
    end

    teardown do
      File.unlink(@filename)
    end

    should "add the given text after the specified text" do
      add_after @filename, "first line", "middle line" 
      assert_equal "first line\nmiddle line\nsecond line\n", File.read(@filename)
    end

    should "not add the given text if it already exists after the specified text" do
      add_after @filename, "first line", "middle line" 
      assert_equal "first line\nmiddle line\nsecond line\n", File.read(@filename)
      add_after @filename, "first line", "middle line" 
      assert_equal "first line\nmiddle line\nsecond line\n", File.read(@filename)
    end

    should "add the given text if it exists but only elsewhere in the specified text" do
      add_after @filename, "first line", "middle line"
      assert_equal "first line\nmiddle line\nsecond line\n", File.read(@filename)
      add_after @filename, "first line", "second line"
      assert_equal "first line\nsecond line\nmiddle line\nsecond line\n", File.read(@filename)
    end
  end

  context "#append_file" do
    setup do
      @filename = 'test.file'
      File.open(@filename,'w') do |f|
        f.puts "first line"
        f.puts "second line"
      end
    end

    teardown do
      File.unlink(@filename)
    end

    should "add text to the end of the file" do
      append_file @filename, "third line"
      assert_equal "first line\nsecond line\nthird line", File.read(@filename)
    end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
jackdempsey-beet-0.1.4 test/file_system_test.rb
jackdempsey-beet-0.1.5 test/file_system_test.rb
jackdempsey-beet-0.1.6 test/file_system_test.rb
jackdempsey-beet-0.1.7 test/file_system_test.rb
jackdempsey-beet-0.1.8 test/file_system_test.rb
jackdempsey-beet-0.1.9 test/file_system_test.rb
jackdempsey-beet-0.2.0 test/file_system_test.rb
jackdempsey-beet-0.2.1 test/file_system_test.rb
jackdempsey-beet-0.2.2 test/file_system_test.rb
jackdempsey-beet-0.3.0 test/file_system_test.rb
jackdempsey-beet-0.3.1 test/file_system_test.rb
whtt-eric-beet-0.6.11 test/file_system_test.rb
whtt-eric-beet-0.6.10 test/file_system_test.rb
beet-0.6.9 test/file_system_test.rb
beet-0.6.8 test/file_system_test.rb
beet-0.6.7 test/file_system_test.rb
beet-0.6.6 test/file_system_test.rb
beet-0.6.5 test/file_system_test.rb
beet-0.6.4 test/file_system_test.rb
beet-0.6.3 test/file_system_test.rb