Sha256: b504eb70bb07267465010c781cd99d9ddc08e988600f726aa6827e793c610208

Contents?: true

Size: 877 Bytes

Versions: 3

Compression:

Stored size: 877 Bytes

Contents

# encoding: utf-8

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

  include Nanoc::TestHelpers

  include Nanoc::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 = Nanoc::Item.new('moo', {}, '/blah/')
    result = ::ERB.new(content).result(binding)

    # Check
    assert_equal '3', content_for(@item, :sidebar).strip
    assert_equal '3', @item[:content_for_sidebar].strip
    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

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-3.3.2 test/helpers/test_capturing.rb
nanoc-3.3.1 test/helpers/test_capturing.rb
nanoc-3.3.0 test/helpers/test_capturing.rb