Sha256: 35fe0f55e6c39a93f771bdda8470b920555a301487532c87e498103a8f4f4b3a

Contents?: true

Size: 809 Bytes

Versions: 2

Compression:

Stored size: 809 Bytes

Contents

# encoding: utf-8

require 'test/helper'

class Nanoc3::Helpers::CapturingTest < MiniTest::Unit::TestCase

  include Nanoc3::TestHelpers

  include Nanoc3::Helpers::Capturing

  def test_content_for
    require 'erb'

    # Build content to be evaluated
    content = "head <% content_for :sidebar do %>\n" +
              "  <%= 1+2 %>\n" +
              "<% end %> foot"

    # Evaluate content
    @item = {}
    result = ::ERB.new(content).result(binding)

    # Check
    assert(@item[:content_for_sidebar].strip == '3')
    assert_match(/^head\s+foot$/, result)
  end

  def test_capture
    require 'erb'

    # Capture
    _erbout = 'foo'
    captured_content = capture do
      _erbout << 'bar'
    end

    # Check
    assert_equal 'foo', _erbout
    assert_equal 'bar', captured_content
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nanoc3-3.1.9 test/helpers/test_capturing.rb
nanoc3-3.1.8 test/helpers/test_capturing.rb