mustache 0.99.4 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +183 -183
  3. data/Rakefile +6 -14
  4. data/bin/mustache +28 -14
  5. data/lib/mustache/context.rb +98 -46
  6. data/lib/mustache/context_miss.rb +55 -0
  7. data/lib/mustache/enumerable.rb +3 -0
  8. data/lib/mustache/generator.rb +63 -42
  9. data/lib/mustache/parser.rb +173 -65
  10. data/lib/mustache/settings.rb +84 -24
  11. data/lib/mustache/template.rb +74 -4
  12. data/lib/mustache/utils.rb +31 -0
  13. data/lib/mustache/version.rb +1 -1
  14. data/lib/mustache.rb +116 -96
  15. data/man/mustache.1 +25 -40
  16. data/man/mustache.1.html +90 -81
  17. data/man/mustache.1.ron +6 -6
  18. data/man/mustache.5 +338 -298
  19. data/man/mustache.5.html +400 -115
  20. data/man/mustache.5.ron +292 -32
  21. data/test/autoloading_test.rb +7 -3
  22. data/test/fixtures/comments.rb +0 -1
  23. data/test/fixtures/complex_view.rb +0 -1
  24. data/test/fixtures/crazy_recursive.rb +0 -1
  25. data/test/fixtures/delimiters.rb +0 -1
  26. data/test/fixtures/dot_notation.rb +0 -1
  27. data/test/fixtures/double_section.rb +0 -1
  28. data/test/fixtures/inverted_section.rb +0 -1
  29. data/test/fixtures/lambda.rb +0 -1
  30. data/test/fixtures/liberal.mustache +1 -0
  31. data/test/fixtures/liberal.rb +25 -0
  32. data/test/fixtures/method_missing.rb +0 -1
  33. data/test/fixtures/namespaced.rb +0 -1
  34. data/test/fixtures/nested_objects.rb +0 -1
  35. data/test/fixtures/override/passenger.conf +6 -0
  36. data/test/fixtures/partial_with_module.rb +0 -1
  37. data/test/fixtures/passenger.rb +0 -1
  38. data/test/fixtures/recursive.rb +0 -1
  39. data/test/fixtures/simple.rb +0 -1
  40. data/test/fixtures/simply_complicated.mustache +25 -0
  41. data/test/fixtures/template_partial.rb +0 -1
  42. data/test/fixtures/unescaped.rb +0 -1
  43. data/test/helper.rb +5 -2
  44. data/test/mustache_test.rb +210 -25
  45. data/test/parser_test.rb +90 -7
  46. data/test/partial_test.rb +16 -4
  47. data/test/path_test.rb +49 -0
  48. data/test/spec_test.rb +5 -5
  49. data/test/template_test.rb +35 -3
  50. metadata +37 -59
  51. data/lib/mustache/sinatra.rb +0 -186
  52. data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +0 -27
  53. data/lib/rack/bug/panels/mustache_panel/view.mustache +0 -46
  54. data/lib/rack/bug/panels/mustache_panel.rb +0 -81
@@ -1,8 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
- $LOAD_PATH.unshift File.dirname(__FILE__)
3
- require 'helper'
2
+ require_relative 'helper'
3
+ require 'json'
4
4
 
5
- class MustacheTest < Test::Unit::TestCase
5
+ class MustacheTest < Minitest::Test
6
6
  def test_instance_render
7
7
  klass = Class.new(Mustache)
8
8
  klass.template = "Hi {{thing}}!"
@@ -15,7 +15,7 @@ end_simple
15
15
  end
16
16
 
17
17
  def test_passenger
18
- assert_equal <<-end_passenger, Passenger.to_text
18
+ assert_equal <<-end_passenger, Passenger.render
19
19
  <VirtualHost *>
20
20
  ServerName example.com
21
21
  DocumentRoot /var/www/example.com
@@ -66,6 +66,14 @@ end_complex
66
66
  instance.render
67
67
  end
68
68
 
69
+ def test_empty_string_as_section_does_not_render_inverted
70
+ instance = Mustache.new
71
+ instance[:value] = ""
72
+ instance.template = "{{#value}}Value Found{{/value}}{{^value}}Value Not Found{{/value}}"
73
+
74
+ assert_equal "Value Found", instance.render
75
+ end
76
+
69
77
  def test_sassy_single_line_sections
70
78
  instance = Mustache.new
71
79
  instance[:full_time] = true
@@ -279,14 +287,19 @@ data
279
287
  RailsEnv production
280
288
  </VirtualHost>
281
289
  data
282
- old_path, Mustache.template_path = Mustache.template_path, File.dirname(__FILE__) + "/fixtures"
283
- old_extension, Mustache.template_extension = Mustache.template_extension, "conf"
284
-
285
- assert_equal expected, Mustache.render(:passenger, :stage => 'production',
286
- :server => 'example.com',
287
- :deploy_to => '/var/www/example.com' )
290
+ old_path = Mustache.template_path
291
+ old_extension = Mustache.template_extension
288
292
 
289
- Mustache.template_path, Mustache.template_extension = old_path, old_extension
293
+ begin
294
+ Mustache.template_path = File.dirname(__FILE__) + "/fixtures"
295
+ Mustache.template_extension = "conf"
296
+
297
+ assert_equal expected, Mustache.render(:passenger, :stage => 'production',
298
+ :server => 'example.com',
299
+ :deploy_to => '/var/www/example.com')
300
+ ensure
301
+ Mustache.template_path, Mustache.template_extension = old_path, old_extension
302
+ end
290
303
  end
291
304
 
292
305
  def test_doesnt_execute_what_it_doesnt_need_to
@@ -344,6 +357,63 @@ data
344
357
  assert_equal ' <li>1234</li> ', instance.render
345
358
  end
346
359
 
360
+ def test_enumerable_sections_enumerate_mustache_enumerables
361
+ person = Struct.new(:name, :age)
362
+ people_array = []
363
+ people_array << person.new('Juliet', 13)
364
+ people_array << person.new('Romeo', 16)
365
+ people = Class.new do
366
+ include Enumerable
367
+ include Mustache::Enumerable
368
+
369
+ def initialize array
370
+ @people = array
371
+ end
372
+
373
+ def each *args, &block
374
+ @people.each(*args, &block)
375
+ end
376
+ end
377
+
378
+ view = Mustache.new
379
+ view[:people] = people.new(people_array)
380
+ view.template = <<-TEMPLATE
381
+ {{#people}}
382
+ {{name}} is {{age}}
383
+ {{/people}}
384
+ TEMPLATE
385
+ assert_equal <<-EXPECTED, view.render
386
+ Juliet is 13
387
+ Romeo is 16
388
+ EXPECTED
389
+ end
390
+
391
+ def test_enumerable_sections_do_not_enumerate_untagged_enumerables
392
+ people = Struct.new(:first, :second, :third)
393
+ person = Struct.new(:name, :age)
394
+
395
+ view = Mustache.new
396
+ view[:people] = people.new(person.new("Mercutio", 17), person.new("Tybalt", 20), person.new("Benvolio", 15))
397
+ view.template = <<-TEMPLATE
398
+ {{#people}}
399
+ {{#first}}
400
+ {{name}} is {{age}}
401
+ {{/first}}
402
+ {{#second}}
403
+ {{name}} is {{age}}
404
+ {{/second}}
405
+ {{#third}}
406
+ {{name}} is {{age}}
407
+ {{/third}}
408
+ {{/people}}
409
+ TEMPLATE
410
+ assert_equal <<-EXPECTED, view.render
411
+ Mercutio is 17
412
+ Tybalt is 20
413
+ Benvolio is 15
414
+ EXPECTED
415
+ end
416
+
347
417
  def test_not_found_in_context_renders_empty_string
348
418
  instance = Mustache.new
349
419
  instance.template = '{{#list}} <li>{{item}}</li> {{/list}}'
@@ -369,10 +439,33 @@ data
369
439
  end
370
440
  end
371
441
 
442
+ def test_not_found_deep_in_context_raises_when_asked_to
443
+ instance = Mustache.new
444
+ instance.raise_on_context_miss = true
445
+
446
+ instance[:list] = { :item => { :value => 1234 } }
447
+
448
+ instance.template = '{{list.item.no_value}}'
449
+
450
+ assert_raises Mustache::ContextMiss do
451
+ instance.render
452
+ end
453
+ end
454
+
455
+ def test_found_in_nested_context_when_asked_to_raise
456
+ instance = Mustache.new
457
+ instance.raise_on_context_miss = true
458
+
459
+ instance[:item] = { :list => [ { :value => 1235, :deep_list => [{:x => 'y'}]}] }
460
+
461
+ instance.template = '{{#item.list}}{{#deep_list}}{{value}}{{/deep_list}}{{/item.list}}'
462
+ assert_equal '1235', instance.render
463
+ end
464
+
372
465
  def test_knows_when_its_been_compiled_when_set_with_string
373
466
  klass = Class.new(Mustache)
374
467
 
375
- assert ! klass.compiled?
468
+ refute klass.compiled?
376
469
  klass.template = 'Hi, {{person}}!'
377
470
  assert klass.compiled?
378
471
  end
@@ -381,28 +474,29 @@ data
381
474
  klass = Class.new(Simple)
382
475
  klass.template_file = File.dirname(__FILE__) + '/fixtures/simple.mustache'
383
476
 
384
- assert ! klass.compiled?
477
+ refute klass.compiled?
385
478
  klass.render
386
479
  assert klass.compiled?
387
480
  end
388
481
 
389
482
  def test_an_instance_knows_when_its_class_is_compiled
390
- instance = Simple.new
483
+ klass = Class.new(Simple)
484
+ instance = klass.new
391
485
 
392
- assert ! Simple.compiled?
393
- assert ! instance.compiled?
486
+ refute klass.compiled?, "Simple was already compiled (from class)."
487
+ refute instance.compiled?, "Simple was already compiled (from instance)."
394
488
 
395
- Simple.render
489
+ klass.render
396
490
 
397
- assert Simple.compiled?
398
- assert instance.compiled?
491
+ assert klass.compiled?, "Simple was not compiled (from class)."
492
+ assert instance.compiled?, "Simple was not compiled (from instance)."
399
493
  end
400
494
 
401
495
  def test_knows_when_its_been_compiled_at_the_instance_level
402
496
  klass = Class.new(Mustache)
403
497
  instance = klass.new
404
498
 
405
- assert ! instance.compiled?
499
+ refute instance.compiled?
406
500
  instance.template = 'Hi, {{person}}!'
407
501
  assert instance.compiled?
408
502
  end
@@ -421,6 +515,24 @@ data
421
515
  assert_equal 1, view.calls
422
516
  end
423
517
 
518
+ def test_sections_returning_lambdas_get_called_dynamically_with_text
519
+ view = Mustache.new
520
+ view.template = '{{name}}'
521
+ view[:name] = lambda { '{{dynamic_name}}' }
522
+ view[:dynamic_name] = 'Chris'
523
+
524
+ assert_equal "Chris", view.render.chomp
525
+ end
526
+
527
+ def test_sections_returning_lambdas_get_not_called_dynamically_with_text_if_static
528
+ view = Mustache.new :static_lambdas => true
529
+ view.template = '{{name}}'
530
+ view[:name] = lambda { '{{dynamic_name}}' }
531
+ view[:dynamic_name] = 'Chris'
532
+
533
+ assert_equal "{{dynamic_name}}", view.render.chomp
534
+ end
535
+
424
536
  def test_sections_which_refer_to_unary_method_call_them_as_proc
425
537
  kls = Class.new(Mustache) do
426
538
  def unary_method(arg)
@@ -454,6 +566,12 @@ data
454
566
  assert_equal "chris j strath", Mustache.render(template, hash)
455
567
  end
456
568
 
569
+ def test_liberal_tag_names_in_class
570
+ assert_equal <<-end_liberal, Liberal.render
571
+ kevin j sheurs 123 Somewhere St
572
+ end_liberal
573
+ end
574
+
457
575
  def test_nested_sections_same_names
458
576
  template = <<template
459
577
  {{#items}}
@@ -550,7 +668,7 @@ template
550
668
  assert_equal('[ 0 1 2 3 4 5 6 7 8 9 10 ]', MethodMissing.render)
551
669
  end
552
670
 
553
- def test_custom_escaping
671
+ def test_custom_html_escaping
554
672
  view = Class.new(Mustache) do
555
673
  def escapeHTML(str)
556
674
  "pong"
@@ -561,6 +679,17 @@ template
561
679
  assert_equal 'nothing', Mustache.render("{{thing}}", :thing => "nothing")
562
680
  end
563
681
 
682
+ def test_custom_escaping
683
+ view = Class.new(Mustache) do
684
+ def escape(str)
685
+ JSON.dump(str)
686
+ end
687
+ end
688
+
689
+ assert_equal '{ "key": "a\"b" }', view.render('{ "key": {{thing}} }', :thing => 'a"b')
690
+ assert_equal 'nothing', Mustache.render("{{thing}}", :thing => "nothing")
691
+ end
692
+
564
693
  def test_implicit_iterator
565
694
  view = Mustache.new
566
695
  view.template = "{{#people}}* {{.}}\n{{/people}}"
@@ -605,16 +734,37 @@ text
605
734
  base = Class.new(Mustache)
606
735
  tmpl = Class.new(base)
607
736
 
608
- {:template_path => File.expand_path('./foo'),
609
- :template_extension => 'stache',
737
+ {:template_extension => 'stache',
610
738
  :view_namespace => TestNamespace,
611
739
  :view_path => './foo'
612
740
  }.each do |attr, value|
613
741
  base.send("#{attr}=", value)
614
742
  assert_equal value, tmpl.send(attr)
615
743
  end
744
+ attr = :template_path
745
+ value = File.expand_path('./foo')
746
+ base.send("#{attr}=", value)
747
+ assert_equal value, tmpl.send(attr).first
616
748
  end
617
- def test_array_of_arrays
749
+
750
+ def test_hash_default_proc
751
+ template = <<template
752
+ {{greetings.Peter}}
753
+ {{greetings.Paul}}
754
+ {{greetings.Mary}}
755
+ template
756
+ data = {
757
+ 'greetings' => Hash.new { |hash, key| hash[key] = "Hello, #{key}!" }
758
+ }
759
+
760
+ assert_equal <<expected, Mustache.render(template, data)
761
+ Hello, Peter!
762
+ Hello, Paul!
763
+ Hello, Mary!
764
+ expected
765
+ end
766
+
767
+ def test_array_of_arrays
618
768
  template = <<template
619
769
  {{#items}}
620
770
  start
@@ -651,7 +801,8 @@ start
651
801
  end
652
802
  expected
653
803
  end
654
- def test_indentation_again
804
+
805
+ def test_indentation_again
655
806
  template = <<template
656
807
  SELECT
657
808
  {{#cols}}
@@ -674,4 +825,38 @@ FROM
674
825
  DUMMY1
675
826
  template
676
827
  end
828
+
829
+ def test_cast_to_hash_in_context
830
+ hashlike = Object.new
831
+ def hashlike.title
832
+ 'title'
833
+ end
834
+ def hashlike.to_hash
835
+ { title: 'title' }
836
+ end
837
+
838
+ template = '%%{{title}}%%'
839
+
840
+ assert_equal '%%title%%', Mustache.render(template, hashlike)
841
+ end
842
+
843
+ def test_instance_with_initialize_render
844
+ klass = Class.new(Mustache) do
845
+ def initialize(name)
846
+ super
847
+ @name = name
848
+ end
849
+ attr_reader :name
850
+ end
851
+
852
+ klass.template = "Hi {{name}}!"
853
+ assert_equal "Hi Dougal!", klass.new("Dougal").render
854
+ end
855
+
856
+ def test_variable_with_at_name
857
+ instance = Mustache.new
858
+ instance.template = "\t{{#list@home}}a{{/list@home}}"
859
+
860
+ assert_equal "\taa", instance.render(:"list@home" => [1, 2])
861
+ end
677
862
  end
data/test/parser_test.rb CHANGED
@@ -1,7 +1,21 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'helper'
1
+ require_relative 'helper'
2
+
3
+ class ParserTest < Minitest::Test
4
+
5
+ def test_parser_extension
6
+ parser = Mustache::Parser.new
7
+ parser.instance_variable_set :@result, 'zomg'
8
+ Mustache::Parser.add_type(:'@', :'$') do |*args|
9
+ [:mustache, :at_sign, @result, *args]
10
+ end
11
+ assert_match Mustache::Parser.valid_types, '@'
12
+ assert_match Mustache::Parser.valid_types, '$'
13
+ assert_equal [:mustache, :at_sign, 'zomg', 1, 2, 3],
14
+ parser.send('scan_tag_@', 1, 2, 3)
15
+ assert_equal [:mustache, :at_sign, 'zomg', 1, 2, 3],
16
+ parser.send('scan_tag_$', 1, 2, 3)
17
+ end
3
18
 
4
- class ParserTest < Test::Unit::TestCase
5
19
  def test_parser
6
20
  lexer = Mustache::Parser.new
7
21
  tokens = lexer.compile(<<-EOF)
@@ -22,29 +36,32 @@ EOF
22
36
 
23
37
  expected = [:multi,
24
38
  [:static, "<h1>"],
25
- [:mustache, :etag, [:mustache, :fetch, ["header"]]],
39
+ [:mustache, :etag, [:mustache, :fetch, ["header"]], [1, 11]],
26
40
  [:static, "</h1>\n"],
27
41
  [:mustache,
28
42
  :section,
29
43
  [:mustache, :fetch, ["items"]],
44
+ [2, 7],
30
45
  [:multi,
31
46
  [:mustache,
32
47
  :section,
33
48
  [:mustache, :fetch, ["first"]],
49
+ [3, 7],
34
50
  [:multi,
35
51
  [:static, " <li><strong>"],
36
- [:mustache, :etag, [:mustache, :fetch, ["name"]]],
52
+ [:mustache, :etag, [:mustache, :fetch, ["name"]], [4, 19]],
37
53
  [:static, "</strong></li>\n"]],
38
54
  %Q' <li><strong>{{name}}</strong></li>\n',
39
55
  %w[{{ }}]],
40
56
  [:mustache,
41
57
  :section,
42
58
  [:mustache, :fetch, ["link"]],
59
+ [6, 6],
43
60
  [:multi,
44
61
  [:static, " <li><a href=\""],
45
- [:mustache, :etag, [:mustache, :fetch, ["url"]]],
62
+ [:mustache, :etag, [:mustache, :fetch, ["url"]], [7, 19]],
46
63
  [:static, "\">"],
47
- [:mustache, :etag, [:mustache, :fetch, ["name"]]],
64
+ [:mustache, :etag, [:mustache, :fetch, ["name"]], [7, 29]],
48
65
  [:static, "</a></li>\n"]],
49
66
  %Q' <li><a href="{{url}}">{{name}}</a></li>\n',
50
67
  %w[{{ }}]]],
@@ -54,6 +71,7 @@ EOF
54
71
  [:mustache,
55
72
  :section,
56
73
  [:mustache, :fetch, ["empty"]],
74
+ [11, 7],
57
75
  [:multi, [:static, "<p>The list is empty.</p>\n"]],
58
76
  %Q'<p>The list is empty.</p>\n',
59
77
  %w[{{ }}]]]
@@ -69,10 +87,75 @@ EOF
69
87
  [:mustache,
70
88
  :section,
71
89
  [:mustache, :fetch, ["list"]],
90
+ [1, 6],
72
91
  [:multi, [:static, "\t"]],
73
92
  "\t",
74
93
  %w[{{ }}]]]
75
94
 
76
95
  assert_equal expected, tokens
77
96
  end
97
+
98
+ def test_unclosed_section
99
+ lexer = Mustache::Parser.new
100
+ exception = assert_raises Mustache::Parser::SyntaxError do
101
+ lexer.compile("{{#list}}")
102
+ end
103
+
104
+ expected = <<-EOF
105
+ Unclosed section "list"
106
+ Line 1
107
+ {{#list}}
108
+ ^
109
+ EOF
110
+
111
+ assert_equal expected, exception.message
112
+ end
113
+
114
+ def test_closing_unopened
115
+ lexer = Mustache::Parser.new
116
+ exception = assert_raises Mustache::Parser::SyntaxError do
117
+ lexer.compile("{{/list}}")
118
+ end
119
+
120
+ expected = <<-EOF
121
+ Closing unopened "list"
122
+ Line 1
123
+ {{/list}}
124
+ ^
125
+ EOF
126
+
127
+ assert_equal expected, exception.message
128
+ end
129
+
130
+ def test_unclosed_tag
131
+ lexer = Mustache::Parser.new
132
+ exception = assert_raises Mustache::Parser::SyntaxError do
133
+ lexer.compile("{{list")
134
+ end
135
+
136
+ expected = <<-EOF
137
+ Unclosed tag
138
+ Line 1
139
+ {{list
140
+ ^
141
+ EOF
142
+
143
+ assert_equal expected, exception.message
144
+ end
145
+
146
+ def test_illegal_content
147
+ lexer = Mustache::Parser.new
148
+ exception = assert_raises Mustache::Parser::SyntaxError do
149
+ lexer.compile("{{")
150
+ end
151
+
152
+ expected = <<-EOF
153
+ Illegal content in tag
154
+ Line 1
155
+ {{
156
+ ^
157
+ EOF
158
+
159
+ assert_equal expected, exception.message
160
+ end
78
161
  end
data/test/partial_test.rb CHANGED
@@ -1,7 +1,6 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'helper'
1
+ require_relative 'helper'
3
2
 
4
- class PartialTest < Test::Unit::TestCase
3
+ class PartialTest < Minitest::Test
5
4
  def test_view_partial
6
5
  assert_equal <<-end_partial.strip, PartialWithModule.render
7
6
  <h1>Welcome</h1>
@@ -21,6 +20,19 @@ end_partial
21
20
  assert_equal "Again, success!", view.render
22
21
  end
23
22
 
23
+ def test_partial_inlining
24
+ view = Mustache.new :inline_partials_at_compile_time => true
25
+ view.template = '{{> test/fixtures/inner_partial}}'
26
+ view[:title] = 'success'
27
+
28
+ # Test the rendered result first
29
+ assert_equal "Again, success!", view.render
30
+
31
+ # Now the template should be compiled.
32
+ # There should be no :partial instruction as the partial has been in-lined.
33
+ assert_equal false, view.template.tokens.flatten.include?(:partial)
34
+ end
35
+
24
36
  def test_view_partial_inherits_context
25
37
  klass = Class.new(TemplatePartial)
26
38
  view = klass.new
@@ -87,7 +99,7 @@ Welcome
87
99
  end_partial
88
100
  end
89
101
 
90
- def test_recursive_paritals
102
+ def test_recursive_partials
91
103
  assert_equal <<-end_partial, Recursive.render
92
104
  It works!
93
105
  end_partial
data/test/path_test.rb ADDED
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+ require_relative 'helper'
3
+
4
+ class MustacheTest < Minitest::Test
5
+
6
+ def test_default_path
7
+ assert_instance_of Array, Mustache.template_path
8
+ assert_equal 1, Mustache.template_path.size
9
+ assert_includes Mustache.template_path, Dir.pwd
10
+ end
11
+
12
+ def test_set_multiple_paths
13
+ old_path = Mustache.template_path
14
+ Mustache.template_path = "this#{File::PATH_SEPARATOR}that"
15
+ assert_instance_of Array, Mustache.template_path
16
+ assert_equal 2, Mustache.template_path.size
17
+ Mustache.template_path = old_path
18
+ end
19
+
20
+ def test_override_found
21
+
22
+ expected = <<-data
23
+ <VirtualHost *>
24
+ ServerAdmin override@mustache.com
25
+ ServerName example.com
26
+ DocumentRoot /var/www/example.com
27
+ RailsEnv production
28
+ </VirtualHost>
29
+ data
30
+ old_path = Mustache.template_path
31
+ old_extension = Mustache.template_extension
32
+
33
+ begin
34
+ base = File.dirname(__FILE__)
35
+ Mustache.template_extension = "conf"
36
+ Mustache.template_path = "#{base}/fixtures/override:#{base}/fixtures"
37
+ assert_equal expected, Mustache.render(:passenger, :stage => 'production',
38
+ :server => 'example.com',
39
+ :deploy_to => '/var/www/example.com')
40
+ Mustache.template_path = "#{base}/fixtures:#{base}/fixtures/override"
41
+ refute_equal expected, Mustache.render(:passenger, :stage => 'production',
42
+ :server => 'example.com',
43
+ :deploy_to => '/var/www/example.com')
44
+ ensure
45
+ Mustache.template_path, Mustache.template_extension = old_path, old_extension
46
+ end
47
+ end
48
+
49
+ end
data/test/spec_test.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  require 'mustache'
2
2
  require 'tmpdir'
3
3
  require 'yaml'
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
 
6
- # Automatically process !code types into Proc objects
7
- YAML::add_builtin_type('code') { |_, val| eval(val['ruby']) }
6
+ # Calls appropriate method on YAML. See: https://gist.github.com/tenderlove/958999ab4240b93bd3cd
7
+ YAML.add_domain_type(nil, 'code') { |_, val| eval(val['ruby']) }
8
8
 
9
9
  # A simple base class for Mustache specs.
10
10
  # Creates a partials directory, then points a (dynamic) subclass of Mustache at
11
11
  # that directory before each test; the partials directory is destroyed after
12
12
  # each test is run.
13
- class MustacheSpec < Test::Unit::TestCase
13
+ class MustacheSpec < Minitest::Test
14
14
  def setup
15
15
  @partials = File.join(File.dirname(__FILE__), 'partials')
16
16
  Dir.mkdir(@partials)
@@ -59,7 +59,7 @@ Dir[spec_files].each do |file|
59
59
 
60
60
  test_suite.class_eval do
61
61
  spec['tests'].each do |test|
62
- define_method :"test - #{test['name']}" do
62
+ define_method :"test_spec - #{test['name']}" do
63
63
  setup_partials(test)
64
64
  assert_mustache_spec(test)
65
65
  end
@@ -1,7 +1,6 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'helper'
1
+ require_relative 'helper'
3
2
 
4
- class TemplateTest < Test::Unit::TestCase
3
+ class TemplateTest < Minitest::Test
5
4
  def test_compile
6
5
  assert_equal %("foo"), Mustache::Template.new("foo").compile
7
6
  end
@@ -18,3 +17,36 @@ class TemplateTest < Test::Unit::TestCase
18
17
  assert_equal [:multi, [:static, "bar"]], Mustache::Template.new("foo").tokens("bar")
19
18
  end
20
19
  end
20
+
21
+ class TemplateTest2 < Minitest::Test
22
+ def setup
23
+ @@template_text ||= File.read(File.dirname(__FILE__) + "/fixtures/simply_complicated.mustache")
24
+ @template = Mustache::Template.new(@@template_text)
25
+ end
26
+
27
+ def test_tags
28
+ assert_equal [
29
+ "yourname",
30
+ "HOME",
31
+ "friend.name",
32
+ "friend.morr.word",
33
+ "friend.morr.up",
34
+ "friend.morr.awesomesauce",
35
+ "friend.morr.hiss",
36
+ "friend.notinmorr",
37
+ "friend.person",
38
+ "love",
39
+ "triplestash"
40
+ ], @template.tags
41
+ end
42
+
43
+ def test_partials
44
+ assert_equal ["partial1", "partial2"], @template.partials
45
+ end
46
+
47
+ def test_sections
48
+ assert_equal ["friend", "friend.morr"], @template.sections
49
+ end
50
+ end
51
+
52
+