Sha256: 3105db2a6736c0776f682ba15ef20671a3741985ce4933956950c58025f2fa1f

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

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

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

class TestWebsiteManager < Test::Unit::TestCase

  def test_initialize
    wm = Webgen::WebsiteManager.new('.')
    t = wm.templates['default']
    assert_equal('Thomas Leitner', t.author)
    assert(t.paths.length > 0)

    s = wm.styles['1024px']
    assert(s.paths.length > 0)
  end

  def test_create_website
    with_tmpdir do |dir|
      wm = Webgen::WebsiteManager.new(dir)
      wm.create_website
      assert(File.directory?(File.join(dir, 'ext')))
      assert(File.directory?(File.join(dir, 'src')))
      assert(File.file?(File.join(dir, 'README')))
      assert(File.file?(File.join(dir, 'config.yaml')))
    end
  end

  def test_apply_template
    with_tmpdir do |dir|
      wm = Webgen::WebsiteManager.new(dir)
      assert_raise(RuntimeError) { wm.apply_template('default') }

      Dir.mkdir(dir)
      wm.apply_template('default')
      assert(File.directory?(File.join(dir, 'src')))
      assert(File.file?(File.join(dir, 'src', 'index.page')))

      assert_raise(ArgumentError) { wm.apply_template('unknown-template') }
    end
  end

  def test_apply_style
    dir = with_tmpdir
    wm = Webgen::WebsiteManager.new(dir)
    assert_raise(RuntimeError) { wm.apply_style('simple') }

    wm.styles.each do |name, infos|
      Dir.mkdir(dir)
      wm.apply_style(name)
      assert(File.directory?(File.join(dir, 'src')))
      assert(File.file?(File.join(dir, 'src', 'default.template')))
      assert(File.file?(File.join(dir, 'src', 'default.css')))
      FileUtils.rm_rf(dir)
    end
    assert_raise(ArgumentError) { wm.apply_style('unknown-style') }
  end

  def with_tmpdir
    dir = File.join(Dir.tmpdir, 'webgen-' + Process.pid.to_s)
    yield(dir) if block_given?
    dir
  ensure
    FileUtils.rm_rf(dir)
  end

end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
gettalong-webgen-0.5.7.20090227 test/test_websitemanager.rb
thewoolleyman-webgen-0.5.8.20090419 test/test_websitemanager.rb
webgen-0.5.7 test/test_websitemanager.rb