Sha256: e3e01cdf90cc6631580017090b5d4da289f5c471bc2837c399a9ff06027fc2b2

Contents?: true

Size: 1.8 KB

Versions: 176

Compression:

Stored size: 1.8 KB

Contents

require 'contest'
require 'tilt'

class TiltTest < Test::Unit::TestCase
  class MockTemplate
    attr_reader :args, :block
    def initialize(*args, &block)
      @args = args
      @block = block
    end
  end

  test "registering template implementation classes by file extension" do
    Tilt.register('mock', MockTemplate)
  end

  test "an extension is registered if explicit handle is found" do
    Tilt.register('mock', MockTemplate)
    assert Tilt.registered?('mock')
  end

  test "registering template classes by symbol file extension" do
    Tilt.register(:mock, MockTemplate)
  end

  test "looking up template classes by exact file extension" do
    Tilt.register('mock', MockTemplate)
    impl = Tilt['mock']
    assert_equal MockTemplate, impl
  end

  test "looking up template classes by implicit file extension" do
    Tilt.register('mock', MockTemplate)
    impl = Tilt['.mock']
    assert_equal MockTemplate, impl
  end

  test "looking up template classes with multiple file extensions" do
    Tilt.register('mock', MockTemplate)
    impl = Tilt['index.html.mock']
    assert_equal MockTemplate, impl
  end

  test "looking up template classes by file name" do
    Tilt.register('mock', MockTemplate)
    impl = Tilt['templates/test.mock']
    assert_equal MockTemplate, impl
  end

  test "looking up non-existant template class" do
    assert_nil Tilt['none']
  end

  test "accessing template class mappings at Tilt::mappings" do
    assert Tilt.respond_to?(:mappings)
    assert Tilt.mappings.respond_to?(:[])
  end

  test "creating new template instance with a filename" do
    Tilt.register('mock', MockTemplate)
    template = Tilt.new('foo.mock', 1, :key => 'val') { 'Hello World!' }
    assert_equal ['foo.mock', 1, {:key => 'val'}], template.args
    assert_equal 'Hello World!', template.block.call
  end
end

Version data entries

176 entries across 151 versions & 26 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/tilt-1.4.1/test/tilt_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/tilt-1.4.1/test/tilt_test.rb
classiccms-0.7.5 vendor/bundle/gems/tilt-1.3.3/test/tilt_test.rb
classiccms-0.7.4 vendor/bundle/gems/tilt-1.3.3/test/tilt_test.rb
classiccms-0.7.3 vendor/bundle/gems/tilt-1.3.3/test/tilt_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/tilt-1.4.1/test/tilt_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/tilt-1.4.1/test/tilt_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/tilt-1.4.1/test/tilt_test.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_test.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/tilt-1.3.3/test/tilt_test.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/tilt-1.4.1/test/tilt_test.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/tilt-1.4.1/test/tilt_test.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/tilt-1.4.1/test/tilt_test.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/tilt-1.3.4/test/tilt_test.rb
challah-1.0.0 vendor/bundle/gems/tilt-1.4.1/test/tilt_test.rb
classiccms-0.7.2 vendor/bundle/gems/tilt-1.3.3/test/tilt_test.rb
classiccms-0.7.1 vendor/bundle/gems/tilt-1.3.3/test/tilt_test.rb
swipe-rails-0.0.5 vendor/bundle/gems/tilt-1.4.1/test/tilt_test.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_test.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/test/tilt_test.rb