Sha256: a126cc332a14af8596afb6c9f7c69ce3acf849388d9b265492c546ce36d90ee8

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'fileutils'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'flannel'

class Test::Unit::TestCase
  def assert_fail message
    assert false, message
  end
  
  def clear_dir dirname
    Dir.foreach(dirname) do |f|
      path = File.join(dirname, f)
      if f == '.' or f == '..' then 
        next
      elsif 
        File.directory?(path) then FileUtils.rm_rf(path)
      else 
        FileUtils.rm( path )
      end
    end
  end
  
  def assert_doc doc, expected_type, expected_id, expected_text, expected_parent_id=nil, expected_attributes=nil
    assert_not_nil doc
    block = doc.content[0]

    assert_block block, expected_type, expected_id, expected_text, expected_parent_id, expected_attributes
  end
  
  def assert_block block, expected_type, expected_id, expected_text, expected_parent_id=nil, expected_attributes=nil
    header = block.shift
    
    type = header.shift
    assert_equal 2, type.length
    assert_equal :block_type, type[0]
    assert_equal expected_type, type[1]   
    
    id = header.shift
    assert_equal 2, id.length
    assert_equal :block_id, id[0]
    assert_equal expected_id, id[1] 
    
    if expected_parent_id
      parent_id = header.shift
      assert_equal 2, parent_id.length
      assert_equal :parent_id, parent_id[0]
      assert_equal expected_parent_id, parent_id[1] 
    end
    
    attribute_list = header.shift
    assert_equal :attribute_list, attribute_list[0]
    
    if expected_attributes
      attributes = attribute_list.dup
      attributes.shift

      assert_equal expected_attributes.length, attributes.length
      attributes.each do |attribute|
        assert_equal expected_attributes[attribute[0]], attribute[1]
      end
    else
      assert_equal 1, attribute_list.length
    end
       
    assert_equal expected_text, block.shift
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flannel-0.2.10 test/test_helper.rb
flannel-0.2.9 test/test_helper.rb