Sha256: 89df66e3b4bdd7514e8da34f3b945df7a193a8bbd6a81fbe7abaa97b991a2584

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

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

12 entries across 12 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 test/test_websitemanager.rb
gettalong-webgen-0.5.5.20081001 test/test_websitemanager.rb
gettalong-webgen-0.5.5.20081010 test/test_websitemanager.rb
gettalong-webgen-0.5.5.20081012 test/test_websitemanager.rb
gettalong-webgen-0.5.6.20081020 test/test_websitemanager.rb
webgen-0.5.0 test/test_websitemanager.rb
webgen-0.5.4 test/test_websitemanager.rb
webgen-0.5.3 test/test_websitemanager.rb
webgen-0.5.1 test/test_websitemanager.rb
webgen-0.5.2 test/test_websitemanager.rb
webgen-0.5.6 test/test_websitemanager.rb
webgen-0.5.5 test/test_websitemanager.rb