test/unit/directive_elsif_test.rb in masterview-0.2.5 vs test/unit/directive_elsif_test.rb in masterview-0.3.0
- old
+ new
@@ -1,31 +1,33 @@
#!/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, '../../lib/masterview/directives/elsif')
+require File.join( currentPath, '../directive_test_helper' )
+DirectiveTestHelpers.load_masterview_directive('elsif')
class TestElsif < Test::Unit::TestCase
- include MasterView::Directives
+ include DirectiveTestHelpers
- def setup
- @directives = MasterView::DirectiveSet.new
- end
+ Elsif = MasterView::Directives::Elsif # test subject
+ ELEMENT_TAG = 'div'
+
def test_elsif
- parent_tag = MasterView::Tag.new(@directives, 'div', {}, :normal, nil)
- parent_tag.content = ['<% if true %>hello world', '<% end %>']
- elsif_tag = MasterView::Tag.new(@directives, 'bar', {}, :normal, parent_tag)
- @directives.directives = []
+ # 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'
- @directives << Elsif.new(attr_value)
- dcs = @directives.determine_dcs(:stag)
- dcs.context = elsif_tag.create_context
+ create_directive Elsif, attr_value
+ assert_equal 1, element_directives.size, 'clean reset of directives for new element'
- assert_equal "<% elsif #{attr_value} %>", dcs.render.join
- assert_equal "<% if true %>hello world", parent_tag.content.join
- assert_equal "<% end %>", @directives.determine_dcs(:etag).render.join
+ 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