Source

amp / test / test_templates.rb

##################################################################
#                  Licensing Information                         #
#                                                                #
#  The following code is licensed, as standalone code, under     #
#  the Ruby License, unless otherwise directed within the code.  #
#                                                                #
#  For information on the license of this code when distributed  #
#  with and used in conjunction with the other modules in the    #
#  Amp project, please see the root-level LICENSE file.          #
#                                                                #
#  © Michael J. Edgar and Ari Brown, 2009-2010                   #
#                                                                #
##################################################################

require File.join(File.expand_path(File.dirname(__FILE__)), 'testutilities')
require File.expand_path(File.join(File.dirname(__FILE__), "../lib/amp/templates/template"))

class TestTemplates < AmpTestCase
  include Amp::Support  
  
  def setup
    @template = Template.new(:log, :test, :erb, "<%= name %> <%= age %>")
    @hamltemplate = Template.new(:commit, :silly, :haml, "= name\n==Age: \#{age}")
  end
  
  def test_new_template
    assert @template
    assert Template[:log, :test]
  end
  
  def test_unregister
    Template.unregister(:log, :test)
    assert_nil(Template[:log, :test])
  end
  
  # ERb Support
  
  def test_render
    name = "Steve"
    age = 21
    assert_equal "Steve 21", @template.render({}, binding)
  end
  
  def test_locals
    locals = {:name => "Steve", :age => 21}
    assert_equal "Steve 21", @template.render(locals)
  end
  
  # Haml support
  
  def test_haml_render
    name = "Steve"
    age = 21
    assert_equal "Steve\nAge: 21", @hamltemplate.render({}, binding).strip
  end
  
  def test_haml_locals
    locals = {:name => "Steve", :age => 21}
    assert_equal "Steve\nAge: 21", @hamltemplate.render(locals).strip
  end
  
  # RawTemplates
  def test_raw_template
    locals = {:name => "Steve", :age => 21}
    assert_equal "Steve 21", RawERbTemplate.new("name + ' ' + age.to_s").render(locals)
  end
  
  # Indirectly tests FileTemplate
  def test_loading_defaults
    Template.ensure_templates_loaded
    assert Template.templates_loaded?
    assert_not_nil(Template[:mercurial, "default-commit"])
    assert_not_nil(Template[:mercurial, "default-log"])
  end
    
end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.