test/buildmaster/templatelets/tc_attribute.rb in BuildMaster-0.8.1 vs test/buildmaster/templatelets/tc_attribute.rb in BuildMaster-0.9.0

- old
+ new

@@ -2,36 +2,50 @@ require 'common_templatelet_test' $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib') -require 'buildmaster/template_exception' +require 'buildmaster/template_error' require 'buildmaster/templatelets/attribute' module BuildMaster -class AttributeTest < CommonTemplateletTest - def test_should_set_attribute_based_on_evaluation + +class AttributeForTest + def initialize(logger) + @logger = logger + end + + def expression(path) + @logger.expression_called_with(path) + return 'value' + end +end + +context 'AttributeTest' do + include HelperMethods + + setup do + setup_spec + end + + specify 'should_set_attribute_based_on_evaluation' do templatelet = Attribute.new(AttributeForTest.new(self)) target = create_element('a') template_element = create_attribute_element('attr-name', 'expression') expected_pathname = Pathname.new('/path') @source_path = SourceContent.new(expected_pathname, nil) templatelet.process(target, template_element, @source_path) - assert_equal('value', target.attributes['attr-name']) - assert_equal(expected_pathname, @path_logged) + target.attributes['attr-name'].should_equal 'value' + @path_logged.should_equal expected_pathname end - def test_should_check_for_expression_responder + specify 'should_check_for_expression_responder' do target = create_element('a') template_element = create_attribute_element('name', 'eval') source_path = SourceContent.new(Pathname.new('./'), create_element('name')) - begin - Attribute.new(self).process(target, template_element, source_path) - fail('template exception should have been thrown') - rescue TemplateException => e - assert_equal(true, e.message.include?('eval')) - end + attribute = Attribute.new(self) + lambda {attribute.process(target, template_element, source_path)}.should_raise TemplateError end def create_attribute_element(name, eval) element = create_element('attribute') element.attributes['name'] = name @@ -39,19 +53,8 @@ return element end def expression_called_with(path) @path_logged = path - end -end - -class AttributeForTest - def initialize(logger) - @logger = logger - end - - def expression(path) - @logger.expression_called_with(path) - return 'value' end end end