Sha256: 1f01b5f0fe8014e40554a126d1878bb2df69bb325b1c2830a2e9891b09b38c92

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'
require 'minitest/mock'

class ContainerTest < ActiveSupport::TestCase

  ETC = ExpressTemplates::Components

  def any_container
    Class.new(ETC::Container)
  end

  test "a Container is a Component" do
    assert_kind_of ETC::Base, any_container.new
  end

  test "a container has children but initially has none" do
    assert any_container.new.respond_to?(:children)
    assert_equal [], any_container.new.children
  end

  def mock_children
    child1, child2 = Minitest::Mock.new, Minitest::Mock.new
    child1.expect(:compile, '"one"')
    child2.expect(:compile, '"two"')
    return child1, child2
  end

  class TestContainer < ETC::Container
    emits { p { _yield } }
  end

  test "Container#compile calls #compile on its children" do
    container = TestContainer.new
    child1, child2 = mock_children
    container.children = [child1, child2]
    container.compile
    child1.verify
    child2.verify
  end

  test ".render_with_children renders children in place of _yield" do
    container = TestContainer.new
    child1, child2 = mock_children
    container.children = [child1, child2]

    assert_equal "<p>onetwo</p>", eval(container.compile)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
express_templates-0.2.7 test/components/container_test.rb
express_templates-0.2.6 test/components/container_test.rb
express_templates-0.2.5 test/components/container_test.rb
express_templates-0.2.4 test/components/container_test.rb
express_templates-0.2.3 test/components/container_test.rb
express_templates-0.2.2 test/components/container_test.rb