Sha256: d9e4bec40a662a43c8b402adb17ae8ea79080bc368c36dfd157d23989e2c6473

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

require 'test_helper'

class TestToriBackendFileSystem < Test::Unit::TestCase
  setup do
    path = Pathname("test/tmp/tori/store")
    @filesystem = Tori::Backend::FileSystem.new(path)
    File.open(@filesystem.root.join("testfile"), 'w+'){ |f| f.write('text') }
  end

  teardown do
    FileUtils.rm_rf("test/tmp")
  end

  test "#initialize" do
    assert_instance_of Tori::Backend::FileSystem, @filesystem
    assert_raise(ArgumentError){ Tori::Backend::FileSystem.new }
  end

  test "#exist?" do
    assert { true == @filesystem.exist?(".") }
    assert { false == @filesystem.exist?("nothing_file") }
  end

  test "#read" do
    assert { "text" == @filesystem.read("testfile") }
    assert_raise(Errno::ENOENT){ @filesystem.read("nothing_file") }
  end

  test "#path" do
    assert { Pathname.new("test/tmp/tori/store/testfile") == @filesystem.path("testfile") }
  end

  test "#write" do
    @filesystem.write("copyfile", @filesystem.path("testfile"))
    assert { "text" == @filesystem.read("copyfile") }

    File.open(@filesystem.path("testfile")) do |f|
      @filesystem.write("copyfile", f)
    end
    assert { "text" == @filesystem.read("copyfile") }

    @filesystem.write("copyfile", "string")
    assert { "string" == @filesystem.read("copyfile") }

    @filesystem.write(Pathname.new("copyfile"), @filesystem.path("testfile"))
    assert { "text" == @filesystem.read("copyfile") }

    @filesystem.write(Pathname.new("copyfile"), "string")
    assert { "string" == @filesystem.read("copyfile") }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tori-0.2.0 test/test_tori_backend_filesystem.rb
tori-0.1.0 test/test_tori_backend_filesystem.rb
tori-0.0.9 test/test_tori_backend_filesystem.rb
tori-0.0.8 test/test_tori_backend_filesystem.rb
tori-0.0.7 test/test_tori_backend_filesystem.rb