Sha256: 182a98e107dcbb12ccb6023c7923cf1600880e6606f9abe79ef5e198045b7ee7
Contents?: true
Size: 1.69 KB
Versions: 15
Compression:
Stored size: 1.69 KB
Contents
# -*- encoding: utf-8 -*- require 'webgen/test_helper' require 'webgen/destination/file_system' require 'webgen/path' class TestDestinationFileSystem < Minitest::Test def setup @dir = dir = Dir.mktmpdir('test-webgen') @website = Object.new @website.define_singleton_method(:directory) { dir } end def teardown FileUtils.remove_entry_secure(@dir) end def test_initialize dest = Webgen::Destination::FileSystem.new(@website, 'test') assert_equal(File.join(@dir, 'test'), dest.root) dest = Webgen::Destination::FileSystem.new(@website, '/tmp/hallo') assert_equal(File.absolute_path('/tmp/hallo', @website.directory), dest.root) dest = Webgen::Destination::FileSystem.new(@website, '../hallo') assert_equal(File.expand_path(File.join(@dir, '../hallo')), dest.root) end def test_file_methods dest = Webgen::Destination::FileSystem.new(@website, 'test') assert(!dest.exists?('/dir/hallo')) dest.write('/dir/hallo', 'content') assert(File.file?(File.join(dest.root, 'dir/hallo'))) assert(dest.exists?('/dir/hallo')) assert_equal('content', File.read(File.join(dest.root, 'dir/hallo'))) assert_equal('content', dest.read('/dir/hallo')) dest.delete('/dir/hallo') refute(dest.exists?('/dir/hallo')) dest.write('/dir/hallo', Webgen::Path.new('fu') { StringIO.new("contentö")}) assert(dest.exists?('/dir/hallo')) assert_equal('contentö', dest.read('/dir/hallo', 'r:UTF-8')) assert_equal('contentö', File.read(File.join(dest.root, 'dir/hallo'), :mode => 'r:UTF-8')) dest.delete('/dir') refute(dest.exists?('/dir')) dest.write('/dir/', '') assert(File.directory?(File.join(dest.root, 'dir'))) end end
Version data entries
15 entries across 15 versions & 1 rubygems