$:.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/source_content' module BuildMaster context 'LinkTest' do include HelperMethods setup do setup_spec end specify 'should_generate_link_with_relative_path' do target = create_element('div') template_content = < text CONTENT template_document = REXML::Document.new(template_content) template = REXML::XPath.first(template_document, '/root/link') source = create_element('source') link = Link.new(SiteSpec.new) link.process(target, template, SourceContent.new(Pathname.new('doc/doc.html'), source)) actual = REXML::XPath.first(target, 'a') actual.attributes['href'].should_equal '../content/path.html' actual.text.should_equal 'text' end specify 'should_copy_all_attributes' do target = create_element('div') template = create_element('link') template.attributes['href'] = 'content/path.html' template.attributes['attribute1'] = 'value1' template.attributes['attribute2'] = 'value2' source = create_element('source') link = Link.new(SiteSpec.new) link.process(target, template, SourceContent.new(Pathname.new('doc/doc.html'), source)) actual = REXML::XPath.first(target, 'a') actual.attributes['attribute1'].should_equal 'value1' actual.attributes['attribute2'].should_equal 'value2' end specify 'should_handle_absolute_path' do target = create_element('div') template = create_element('link') template.attributes['href'] = '/content/path.html' source = create_element('source') link = Link.new(SiteSpec.new) link.process(target, template, SourceContent.new(Pathname.new('doc/iste/doc.html'), source)) actual = REXML::XPath.first(target, 'a') actual.attributes['href'].should_equal '../../content/path.html' end specify 'should_generate_div_with_current_class_attribute_if_link_is_on_current_page' do target = create_element('div') template = create_element('link') template.attributes['href'] = '/content/path.html' source = create_element('source') link = Link.new(SiteSpec.new) link.process(target, template, SourceContent.new(Pathname.new('content/path.html'), source)) actual = REXML::XPath.first(target, 'div') actual.attributes['href'].should_equal nil actual.attributes['class'].should_equal 'current' end end end