Sha256: 1eb79f77c2aad70bfce6f4730381c0586b957c980dcaedc7f7aa73eea195d061

Contents?: true

Size: 1.76 KB

Versions: 12

Compression:

Stored size: 1.76 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.bundles['default']
    assert_equal('Thomas Leitner', t.author)
    assert(t.paths.length > 0)

    ws = Webgen::Website.new('.')
    wm = Webgen::WebsiteManager.new(ws)
    assert_equal('Thomas Leitner', wm.bundles['default'].author)
  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_bundle
    with_tmpdir do |dir|
      wm = Webgen::WebsiteManager.new(dir)
      assert_raise(RuntimeError) { wm.apply_bundle('default') }

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

      assert_raise(ArgumentError) { wm.apply_bundle('unknown-bundle') }

      FileUtils.rm_rf(dir)
      wm.bundles.select {|n,i| n =~ /^style-/}.each do |name, infos|
        Dir.mkdir(dir)
        wm.apply_bundle(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
    end
  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.8.20090507 test/test_websitemanager.rb
gettalong-webgen-0.5.9.20090620 test/test_websitemanager.rb
gettalong-webgen-0.5.9.20090626 test/test_websitemanager.rb
webgen-0.5.17 test/test_websitemanager.rb
webgen-0.5.15 test/test_websitemanager.rb
webgen-0.5.14 test/test_websitemanager.rb
webgen-0.5.13 test/test_websitemanager.rb
webgen-0.5.12 test/test_websitemanager.rb
webgen-0.5.11 test/test_websitemanager.rb
webgen-0.5.10 test/test_websitemanager.rb
webgen-0.5.9 test/test_websitemanager.rb
webgen-0.5.8 test/test_websitemanager.rb