Sha256: 3a48a49efed5e2561010d474e137ab60b8d25c058c0f7ffb4a15f7441eed2a3b

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8

require 'test/helper'

class Nanoc3::Filters::ERBTest < MiniTest::Unit::TestCase

  include Nanoc3::TestHelpers

  def test_filter_with_instance_variable
    # Create filter
    filter = ::Nanoc3::Filters::ERB.new({ :location => 'a cheap motel' })

    # Run filter
    result = filter.run('<%= "I was hiding in #{@location}." %>')
    assert_equal('I was hiding in a cheap motel.', result)
  end

  def test_filter_with_instance_method
    # Create filter
    filter = ::Nanoc3::Filters::ERB.new({ :location => 'a cheap motel' })

    # Run filter
    result = filter.run('<%= "I was hiding in #{location}." %>')
    assert_equal('I was hiding in a cheap motel.', result)
  end

  def test_filter_error_item
    # Create item and item rep
    item = MiniTest::Mock.new
    item.expect(:identifier, '/foo/bar/baz/')
    item_rep = MiniTest::Mock.new
    item_rep.expect(:name, :quux)

    # Create filter
    filter = ::Nanoc3::Filters::ERB.new({
      :item     => item,
      :item_rep => item_rep,
      :location => 'a cheap motel'
    })

    # Run filter
    raised = false
    begin
      filter.run('<%= this isn\'t really ruby so it\'ll break, muahaha %>')
    rescue SyntaxError => e
      e.message =~ /(.+?):\d+: /
      assert_match 'item /foo/bar/baz/ (rep quux)', $1
      raised = true
    end
    assert raised
  end

  def test_filter_with_yield
    # Create filter
    filter = ::Nanoc3::Filters::ERB.new({ :content => 'a cheap motel' })

    # Run filter
    result = filter.run('<%= "I was hiding in #{yield}." %>')
    assert_equal('I was hiding in a cheap motel.', result)
  end

  def test_filter_with_yield_without_content
    # Create filter
    filter = ::Nanoc3::Filters::ERB.new({ :location => 'a cheap motel' })

    # Run filter
    assert_raises LocalJumpError do
      filter.run('<%= "I was hiding in #{yield}." %>')
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nanoc3-3.1.9 test/filters/test_erb.rb
nanoc3-3.1.8 test/filters/test_erb.rb