$:.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 context 'WhenTest' do include HelperMethods setup do setup_spec end specify 'should_process_child_when_evaluated_true' do target = create_element('target') template_content = <

Header

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') actual.text.should_equal 'Header' end specify 'should_not_process_child_when_evaluated_false' do target = create_element('target') template_content = <

Header

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) target.size.should_equal 0 end def path return Pathname.new('index.html') end def expression_for_true(path) return 'word two' =~ /word/ end def expression_for_false(path) return 'one word two' =~ /nomatch/ end def load_templatelets return Hash.new end end end