#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) #require File.join( currentPath, '../../lib/masterview/directives/elsif') require File.join( currentPath, '../directive_test_helper' ) DirectiveTestHelpers.load_masterview_directive('elsif') class TestElsif < Test::Unit::TestCase include DirectiveTestHelpers Elsif = MasterView::Directives::Elsif # test subject ELEMENT_TAG = 'div' def test_elsif # initial mv:if element gets wrapped by if/end erb conditions tag_content = [ '<% if( true ) -%>hello world', '<% end -%>' ] if_tag = create_template_element ELEMENT_TAG, :content => tag_content elseif_tag = create_template_element ELEMENT_TAG, :parent_tag => if_tag attr_value = '@foobar' create_directive Elsif, attr_value assert_equal 1, element_directives.size, 'clean reset of directives for new element' assert_equal "<% elsif( #{attr_value} ) -%>", render_element_event(:stag) assert_equal "<% if( true ) -%>hello world", if_tag.content.join, 'elseif directive modifies preceding tag by removing its end marker when it adds itself to the output' assert_equal "<% end -%>", render_element_event(:etag) end end