#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) require File.join( currentPath, '../../lib/masterview/directives/attr') class TestAttr < Test::Unit::TestCase include MasterView::Directives def setup @directives = MasterView::DirectiveSet.new @tag = MasterView::Tag.new(@directives, 'foo', {'bar' => 'cat'}, :normal, nil) end def test_hello @directives.directives = [] attr_value = "{:hello => 'world'}" @directives << Attr.new(attr_value) dcs = @directives.determine_dcs(:stag) dcs.context = @tag.create_context assert_equal '', dcs.render.join assert_equal 'cat', dcs.context[:tag].attributes['bar'] assert_equal 'world', dcs.context[:tag].attributes['hello'] end def test_hello_hi @directives.directives = [] attr_value = ":hello => 'world', :hi => 'there'" @directives << Attr.new(attr_value) dcs = @directives.determine_dcs(:stag) dcs.context = @tag.create_context assert_equal '', dcs.render.join assert_equal 'cat', dcs.context[:tag].attributes['bar'] assert_equal 'world', dcs.context[:tag].attributes['hello'] assert_equal 'there', dcs.context[:tag].attributes['hi'] end def test_hello_erb @directives.directives = [] attr_value = %q":hello => 'world', :hi => 'there', :wow => #{h product.name}" @directives << Attr.new(attr_value) dcs = @directives.determine_dcs(:stag) dcs.context = @tag.create_context assert_equal '', dcs.render.join assert_equal 'cat', dcs.context[:tag].attributes['bar'] assert_equal 'world', dcs.context[:tag].attributes['hello'] assert_equal 'there', dcs.context[:tag].attributes['hi'] assert_equal '{{{= h product.name }}}', dcs.context[:tag].attributes['wow'] end end