test/buildmaster/site/tc_template_builder.rb in BuildMaster-0.8.1 vs test/buildmaster/site/tc_template_builder.rb in BuildMaster-0.9.0

- old
+ new

@@ -1,96 +1,97 @@ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib') -require 'test/unit' +require 'spec' require 'rexml/xpath' require 'buildmaster/site/template_builder' require 'buildmaster/tree_to_object' require 'yaml' module BuildMaster -class TemplateBuilderTest < Test::Unit::TestCase - def test_should_generate_template_document +context 'Template Builder' do + + specify 'should generate template document' do builder = TemplateBuilder.new document = builder.generate - assert_equal('include', REXML::XPath.first(document, '/html/head/title/*').name) + REXML::XPath.first(document, '/html/head/title/*').name.should_equal 'include' assert_css_path(document, 'buildmaster.css') end - def test_should_update_header_with_title_and_css + specify 'should update header with title and css' do builder = TemplateBuilder.new builder.title_header = 'Title Header - ' builder.css_path = 'mycss.css' document = builder.generate first_child = REXML::XPath.first(document, '/html/head/title').children[0] - assert_equal(REXML::Text, first_child.class) - assert_equal('Title Header - ', first_child.value) + first_child.class.should_equal REXML::Text + first_child.value.should_equal 'Title Header - ' assert_css_path(document, 'mycss.css') end - def test_should_have_logo_defaults + specify 'test_should_have_logo_defaults' do builder = TemplateBuilder.new - assert_equal(nil, builder.logo.path) - assert_equal('index.html', builder.logo.link) + builder.logo.path.should_equal nil + builder.logo.link.should_equal 'index.html' end - def test_should_generate_logo_and_link + specify 'test_should_generate_logo_and_link' do builder = TemplateBuilder.new builder.logo.path = 'gif/logo.gif' builder.logo.link = 'main.html' document = builder.generate header = assert_first(document, '/html/body/div[@class="header"]') anchor_href = assert_first(header, 'a/template:href') - assert_equal('main.html', anchor_href.attributes['url']) + anchor_href.attributes['url'].should_equal 'main.html' img_href = assert_first(header, 'a/img/template:href') - assert_equal('gif/logo.gif', img_href.attributes['url']) + img_href.attributes['url'].should_equal 'gif/logo.gif' end - def test_should_build_left_menu + specify 'test_should_build_left_menu' do builder = TemplateBuilder.new builder.left_bottom_logo.path='http://www.example.com/logo.gif' group = builder.menu_group('Software') group.menu_item('Download', 'download.html') group.menu_item('License', 'license.html') group.more='more.html' group = builder.menu_group('Documentation', 'doc/index.html') group.menu_item('Getting Started', 'doc/getting-started') document = builder.generate groups = REXML::XPath.match(document, '/html/body/div[@class="left"]/div[@class="MenuGroup"]') - assert_equal(2, groups.size) + groups.size.should_equal 2 first_group = groups[0] header = assert_first(first_group, 'h1') - assert_equal('Software', header.text) + header.text.should_equal 'Software' items = REXML::XPath.match(first_group, 'ul/li') - assert_equal(3, items.size) + items.size.should_equal 3 first_item = items[0] anchor = assert_first(first_item, 'template:link') - assert_equal('download.html', anchor.attributes['href']) - assert_equal('Download', anchor.text) + anchor.attributes['href'].should_equal 'download.html' + anchor.text.should_equal 'Download' more = items[2] - assert_equal('More', more.attributes['class']) + more.attributes['class'].should_equal 'More' end - def test_should_have_releases_info + specify 'should_have_releases_info' do builder = TemplateBuilder.new releases = builder.releases releases.stable_version = '0.6' releases.pre_release_version = '0.7' releases.snap_shot_version = 'n/a' releases.download_link = 'download.html' releases.versioning_link = 'versioning.html' document = builder.generate - assert_equal('Latest Versions', REXML::XPath.first(document, '/html/body/template:when/div[@class="right"]/div/h1').text) + REXML::XPath.first(document, '/html/body/template:when/div[@class="right"]/div/h1').text.should_equal 'Latest Versions' end - def test_should_have_no_release_info_if_not_assigned + specify 'should_have_no_release_info_if_not_assigned' do builder = TemplateBuilder.new builder.releases.download_link = nil document = builder.generate - assert_equal(0, REXML::XPath.match(document, '/html/body/template:when/div/*').size) + REXML::XPath.match(document, '/html/body/template:when/div/*').size.should_equal 0 end - def test_should_read_from_yaml + specify 'should_read_from_yaml' do content = <<CONTENT title_header: BuilderMaster - logo: path: logo.gif link: index.html @@ -113,24 +114,24 @@ - title: Site Building link: build-site.html more: doc/index.html CONTENT builder = TreeToObject.from_yaml(content, TemplateBuilder.new) - assert_equal('BuilderMaster -', builder.title_header) - assert_equal('logo.gif', builder.logo.path) - assert_equal('index.html', builder.logo.link) + builder.title_header.should_equal 'BuilderMaster -' + builder.logo.path.should_equal 'logo.gif' + builder.logo.link.should_equal 'index.html' end private def assert_css_path(document, expected) href = REXML::XPath.first(document, '/html/head/link/*') - assert_equal('href', href.name) - assert_equal(expected, href.attributes['url']) + href.name.should_equal 'href' + href.attributes['url'].should_equal expected end def assert_first(xml_model, xpath) first = REXML::XPath.first(xml_model, xpath) - assert_not_nil(first) + first.should_not_equal nil return first end end end