Sha256: 5093baa86c2bbc0c9f69518959622a0a5cc8a7cf7dca3493b3c91d017b4519a9

Contents?: true

Size: 1.74 KB

Versions: 15

Compression:

Stored size: 1.74 KB

Contents

# -*- encoding: utf-8 -*-

require 'test/unit'
require 'helper'
require 'webgen/output'
require 'tmpdir'
require 'fileutils'

class TestOutputFileSystem < Test::Unit::TestCase

  include Test::WebsiteHelper

  def setup
    super
    @website = Webgen::Website.new(File.join(Dir.tmpdir, 'test_webgen'), nil)
    @website.init
    Thread.current[:webgen_website] = @website
  end

  def teardown
    super
    FileUtils.rm_rf(File.join(Dir.tmpdir, 'test_webgen'))
  end

  def test_initialize
    output = Webgen::Output::FileSystem.new('test')
    assert_equal(File.join(@website.directory, 'test'), output.root)
    output = Webgen::Output::FileSystem.new('/tmp/hallo')
    assert_equal('/tmp/hallo', output.root)
    output = Webgen::Output::FileSystem.new('../hallo')
    assert_equal(File.join(@website.directory, '../hallo'), output.root)
  end

  def test_file_methods
    output = Webgen::Output::FileSystem.new('test')
    assert(!output.exists?('/dir/hallo'))

    output.write('/dir/hallo', 'content', :file)
    assert(File.file?(File.join(output.root, 'dir/hallo')))
    assert(output.exists?('/dir/hallo'))
    assert_equal('content', File.read(File.join(output.root, 'dir/hallo')))
    assert_equal('content', output.read('/dir/hallo'))

    output.delete('/dir/hallo')
    assert(!output.exists?('/dir/hallo'))

    output.write('/dir/hallo', Webgen::Path::SourceIO.new { StringIO.new('content')}, :file)
    assert_equal('content', File.read(File.join(output.root, 'dir/hallo')))
    assert(output.exists?('/dir/hallo'))

    output.delete('/dir')
    assert(!output.exists?('/dir'))

    output.write('/dir', '', :directory)
    assert(File.directory?(File.join(output.root, 'dir')))

    assert_raise(RuntimeError) { output.write('other', '', :unknown) }
  end

end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
gettalong-webgen-0.5.7.20090227 test/test_output_filesystem.rb
gettalong-webgen-0.5.8.20090507 test/test_output_filesystem.rb
gettalong-webgen-0.5.9.20090620 test/test_output_filesystem.rb
gettalong-webgen-0.5.9.20090626 test/test_output_filesystem.rb
thewoolleyman-webgen-0.5.8.20090419 test/test_output_filesystem.rb
webgen-0.5.17 test/test_output_filesystem.rb
webgen-0.5.15 test/test_output_filesystem.rb
webgen-0.5.14 test/test_output_filesystem.rb
webgen-0.5.13 test/test_output_filesystem.rb
webgen-0.5.12 test/test_output_filesystem.rb
webgen-0.5.11 test/test_output_filesystem.rb
webgen-0.5.10 test/test_output_filesystem.rb
webgen-0.5.9 test/test_output_filesystem.rb
webgen-0.5.7 test/test_output_filesystem.rb
webgen-0.5.8 test/test_output_filesystem.rb