Sha256: 9defa1ea4d58a8b8cbb8e60bcf0f4d9ae2e4014379ff480d5e51fa314176362e

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

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

4 entries across 4 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.5.20081010 test/test_output_filesystem.rb
gettalong-webgen-0.5.5.20081012 test/test_output_filesystem.rb
gettalong-webgen-0.5.6.20081020 test/test_output_filesystem.rb
webgen-0.5.6 test/test_output_filesystem.rb