Sha256: b3ca8fb68acc5a7ef415b004f123f2b98947b94af2d7bc7e5fcab3154a01612d

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

$:.unshift File.dirname(__FILE__)

require 'common_templatelet_test'

$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')

require 'rexml/document'
require 'rexml/xpath'
require 'buildmaster/site_spec'
require 'buildmaster/templatelets'

module BuildMaster
class WhenTest < CommonTemplateletTest
  def test_should_process_child_when_evaluated_true
    target = create_element('target')
    template_content = <<CONTENT
<when test='expression_for_true'>
  <h1>Header</h1>
</when>
CONTENT
    template_document = REXML::Document.new(template_content)
    template = REXML::XPath.first(template_document, '/when')
    when_processor = When.new(self, self)
    when_processor.process(target, template, self)
    actual = REXML::XPath.first(target, 'h1')
    assert_equal('Header', actual.text)
  end
  
  def test_should_not_process_child_when_evaluated_false
    target = create_element('target')
    template_content = <<CONTENT
<when test='expression_for_false'>
  <h1>Header</h1>
</when>
CONTENT
    template_document = REXML::Document.new(template_content)
    template = REXML::XPath.first(template_document, '/when')
    when_processor = When.new(self, self)
    when_processor.process(target, template, self)
    assert_equal(0, target.size)
  end
  
  def path
    return Pathname.new('index.html')
  end
  
  def expression_for_true(path)
    return true
  end
  
  def expression_for_false(path)
    return false
  end
  
  def load_templatelets
    return Hash.new
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
BuildMaster-0.8.0 test/buildmaster/templatelets/tc_when.rb