Sha256: 39465a89da31b38a45e69f2f99a8d735062c66ed501cd538034bacdf74402339

Contents?: true

Size: 881 Bytes

Versions: 8

Compression:

Stored size: 881 Bytes

Contents

# encoding: utf-8

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 = Nanoc3::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

8 entries across 8 versions & 1 rubygems

Version Path
nanoc3-3.2.4 test/helpers/test_capturing.rb
nanoc3-3.2.3 test/helpers/test_capturing.rb
nanoc3-3.2.2 test/helpers/test_capturing.rb
nanoc3-3.2.1 test/helpers/test_capturing.rb
nanoc3-3.2.0 test/helpers/test_capturing.rb
nanoc3-3.2.0b3 test/helpers/test_capturing.rb
nanoc3-3.2.0b2 test/helpers/test_capturing.rb
nanoc3-3.2.0b1 test/helpers/test_capturing.rb