File: autoloading_test.rb

package info (click to toggle)
ruby-mustache 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 480 kB
  • sloc: ruby: 2,267; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require_relative 'helper'

module TestViews; end

class AutoloadingTest < Minitest::Test
  def setup
    Mustache.view_path = File.dirname(__FILE__) + '/fixtures'
  end

  def teardown
    Mustache.remove_instance_variable(:@view_namespace) if Mustache.instance_variable_defined?(:@view_namespace)
  end

  def test_autoload
    klass = Mustache.view_class(:Comments)
    assert_equal Comments, klass
  end

  def test_autoload_lowercase
    klass = Mustache.view_class(:comments)
    assert_equal Comments, klass
  end

  def test_autoload_nil
    klass = Mustache.view_class(nil)
    assert_equal Mustache, klass
  end

  def test_autoload_empty_string
    klass = Mustache.view_class('')
    assert_equal Mustache, klass
  end

  def test_namespaced_autoload
    Mustache.view_namespace = TestViews
    klass = Mustache.view_class('Namespaced')
    assert_equal TestViews::Namespaced, klass
    assert_equal <<-end_render.strip, klass.render
<h1>Dragon &lt; Tiger</h1>
end_render
  end

  def test_folder_autoload
    assert_equal TestViews::Namespaced, Mustache.view_class('test_views/namespaced')
  end

  def test_namespaced_partial_autoload
    Mustache.view_namespace = TestViews
    klass = Mustache.view_class(:namespaced_with_partial)
    assert_equal TestViews::NamespacedWithPartial, klass
    assert_equal <<-end_render.strip, klass.render
My opinion: Again, Victory!
end_render
  end

  def test_bad_constant_name
    assert_equal Mustache, Mustache.view_class(404)
  end
end