$:.unshift File.dirname(__FILE__) require 'common_templatelet_test' $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib') module BuildMaster class HrefTest < CommonTemplateletTest def setup super @template_element = create_element('href') @target_element = create_element('a') @href = Href.new(@site_spec) end def source(path) SourceContent.new(Pathname.new(path), nil) end def test_should_populate_href_attribute_with_full_url expected_url = 'http://www.rubyforge.org' @template_element.attributes['url']=expected_url @href.process(@target_element, @template_element, source('index.html')) assert_equal(expected_url, @target_element.attributes['href']) end def test_should_populate_href_attribute_with_relative_path @template_element.attributes['url']='doc/doc.html' @href.process(@target_element, @template_element, source('download/index.html')) assert_equal('../doc/doc.html', @target_element.attributes['href']) end def test_should_support_image_tag_by_generating_src_attribute @template_element.attributes['url']='doc/doc.gif' @target_element = create_element('img') @href.process(@target_element, @template_element, source('download/download.html')) assert_equal('../doc/doc.gif', @target_element.attributes['src']) end def test_should_handle_external_links @template_element.attributes['url'] = 'http://www.google.com' @target_element = create_element('img') @href.process(@target_element, @template_element, source('download/download.html')) assert_equal('http://www.google.com', @target_element.attributes['src']) end end end