Sha256: b5729ff5316b80ab377ddd6c65fcd27f80fe7c54b1bbcf637c4312dda2788470

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 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") }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tori-0.0.6 test/test_tori_backend_filesystem.rb
tori-0.0.5 test/test_tori_backend_filesystem.rb