$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib") require 'test/unit' require 'buildmaster' module BuildMaster class SiteSpecTest < Test::Unit::TestCase def test_should_get_relative_path spec = SiteSpec.new spec.content_dir = '/one/two/content' assert_equal('images/logo.gif', spec.relative_to_root('/one/two/content/images/logo.gif').to_s) end def test_should_support_windows_path spec = SiteSpec.new spec.content_dir = "C:\\Work\\project\\content" assert_equal('images/logo.gif', spec.relative_to_root('C:\\Work\\project\\content\\images\\logo.gif').to_s) end def test_should_evaluate spec = SampleSiteSpec.new spec.content_dir = '/one/two/content' result = spec.evaluate('expression', '/one/two/content/dir/file.txt') assert_equal('dir/file.txt', result) end def test_should_check_for_property spec = SiteSpec.new spec.content_dir = "/one" spec.add_property('release', '0.6') assert_equal('0.6', spec.evaluate('release', '/one')) end def test_should_throw_error_with_proper_message_for_expression_problem spec = SiteSpec.new spec.content_dir = "/one" begin spec.evaluate('expression', '/one/two') fail('exception should have been thrown') rescue RuntimeError => boom assert_equal("Neither property nor method found with name 'expression'", boom.message) end end def test_relative_to_root_expression spec = SiteSpec.new spec.content_dir = '/one' actual = spec.evaluate('relative_to_root', '/one/two') assert_equal(Pathname.new('two'), actual) end end class SampleSiteSpec < SiteSpec private def expression(path) return path end def expression2 return 'expected' end end end