require 'test_helper' class SimpleBuilderTest < ActionView::TestCase def setup @template = self end def test_render_should_be_implemented assert_nothing_raised { simplebuilder(@template, []).render } end def test_render_with_0_elements assert_equal("", simplebuilder(@template, []).render) end def test_render_with_0_elements_and_separator assert_equal("", simplebuilder(@template, [], :separator => "-").render) end def test_render_with_1_element @template.expects(:current_page?).times(1).returns(false) assert_dom_equal("Element 1", simplebuilder(@template, generate_elements(1)).render) end def test_render_with_1_element_and_separator @template.expects(:current_page?).times(1).returns(false) assert_dom_equal("Element 1", simplebuilder(@template, generate_elements(1), :separator => "-").render) end def test_render @template.expects(:current_page?).times(2).returns(false) assert_dom_equal("Element 1 » Element 2", simplebuilder(@template, generate_elements(2)).render) end def test_render_with_separator @template.expects(:current_page?).times(2).returns(false) assert_dom_equal("Element 1 - Element 2", simplebuilder(@template, generate_elements(2), :separator => " - ").render) end def test_render_with_current_page @template.expects(:current_page?).times(2).returns(false, true) assert_dom_equal("Element 1 » Element 2", simplebuilder(@template, generate_elements(2)).render) end protected def simplebuilder(*args) Ramenu::Menus::SimpleBuilder.new(*args) end def generate_elements(number) (1..number).collect do |index| Ramenu::Menus::Element.new("Element #{index}", "/element/#{index}") end end end