Sha256: 38813f8d77f1d8857b42f500b2fd2220db0aa59f3ea7476cc8c5aa70b03fbe8c

Contents?: true

Size: 2 KB

Versions: 5

Compression:

Stored size: 2 KB

Contents

require File.expand_path('../../helper', __FILE__)

class HydeTest < TestCase
  def assert_fixture_works(path)
    build_fixture(path) { |control, var|
      assert File.exists?(var)
      if read(control) != read(var)
        flunk "Failed in #{var}\n" +
          "Control:\n" +
          read(control).gsub(/^/, '|    ') + "\n\n" + 
          "Variable:\n" +
          read(var).gsub(/^/, '|    ')
      end
    }
  end

  def assert_fixture_fails(path, error=Hyde::Error, &blk)
    begin
      build_fixture(path)
    rescue error => e
      yield e
    else
      flunk "Assertion failed"
    end
  end


  def build_fixture(path, &blk)
    # Build
    project = build path

    assert \
      Dir[project.root('control/**/*')].length == 
      Dir[project.root('public/**/*')].length

    Dir[project.root('control/**/*')].each do |control|
      next  unless File.file?(control)
      var = control.sub('/control/', '/public/')
      yield control, var
    end   if block_given?
  end

  def read(file)
    File.open(file) { |f| f.read }
  end

  teardown do
    # Remove the generated
    Dir[fixture('*', 'public')].each { |dir| FileUtils.rm_rf dir }
  end

  test "fixture one" do
    assert_fixture_works fixture('one')
  end

  test "fixture subclass" do
    assert_fixture_works fixture('subclass')
  end

  test "fixture extensions" do
    assert_fixture_works fixture('extensions')
  end

  test "fixture parent" do
    assert_fixture_works fixture('parent')
  end

  test "fixture sort" do
    assert_fixture_works fixture('sort')
  end

  test "fixture ignores" do
    assert_fixture_works fixture('ignores')
  end

  test "fixture metadata" do
    assert_fixture_works fixture('metadata')
  end

  test "fixture nested_layout" do
    assert_fixture_works fixture('nested_layout')
  end
  
  test "fixture build_options" do
    assert_fixture_works fixture('build_options')
  end

  test "fixture fail_type" do
    assert_fixture_fails(fixture('fail_type')) { |e|
      assert e.message.include?('nonexistent')
    }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hydeweb-0.1.14 test/unit/fixture_test.rb
hydeweb-0.1.13 test/unit/fixture_test.rb
hydeweb-0.1.12 test/unit/fixture_test.rb
hydeweb-0.1.11 test/unit/fixture_test.rb
hydeweb-0.1.10 test/unit/fixture_test.rb