Sha256: c93f5d4b9455fe4d400b072612a2af010313a09ec1fecff92ffc54ee489aa2a0

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'

class TestToriFile < Test::Unit::TestCase
  setup do
    @orig = Tori.config.filename_callback
    Tori.config.filename_callback do |model|
      model
    end
    Tori.config.backend = Tori::Backend::FileSystem.new Pathname("test").join("tmp")
  end

  teardown do
    Tori.config.filename_callback &@orig
    FileUtils.rm_rf("test/tmp")
  end

  class From
    def path
      __FILE__
    end
  end

  test "#initialize" do
    assert_instance_of Tori::File, Tori::File.new(nil)
    assert_instance_of Tori::File, Tori::File.new(nil, from: nil)
  end

  test "#name" do
    assert { "test" == Tori::File.new("test").name }
  end

  test "#exist?" do
    assert { true == Tori::File.new(__FILE__).exist? }
    assert { false == Tori::File.new("nothing_file").exist? }
  end

  test "#from?" do
    assert { false == Tori::File.new(__FILE__).from? }
    assert { true == Tori::File.new(__FILE__, from: From.new).from? }
  end

  test "write" do
    assert { false == File.exist?("test/tmp/copy") }
    Tori::File.new("copy", from: From.new).write
    assert { true == File.exist?("test/tmp/copy") }
  end

  test "#method_missing" do
    assert { true == Tori::File.new(nil).respond_to?(:read) }
    assert_raise(NameError) { Tori::File.new(nil).undefined }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tori-0.0.8 test/test_tori_file.rb
tori-0.0.7 test/test_tori_file.rb
tori-0.0.6 test/test_tori_file.rb