Sha256: 04ef3933294cf51fc7b97e8c2b9a19cf1ae78b67016b66020bc340ea2c5e24f0

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

$:.unshift File.dirname(__FILE__)

require 'common_templatelet_test'

$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')

require 'buildmaster/template_error'
require 'buildmaster/templatelets/attribute'

module BuildMaster

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)
    target.attributes['attr-name'].should_equal 'value'
    @path_logged.should_equal expected_pathname
  end
  
  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'))
    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
    element.attributes['eval'] = eval
    return element
  end
  
  def expression_called_with(path)
    @path_logged = path
  end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
BuildMaster-0.9.0 test/buildmaster/templatelets/tc_attribute.rb
BuildMaster-0.9.1 test/buildmaster/templatelets/tc_attribute.rb