require 'test_helper' require 'pry' class HandlerTest < ActiveSupport::TestCase GARAHandler = Gara::Template::Handler.new DEFAULT_DOCTYPE = "" A_LINK = %Q(link) class LookupContext def disable_cache yield end def find_template(*args) end attr_accessor :formats end class Context def initialize @output_buffer = "original" @virtual_path = nil end def lookup_context @lookup_context ||= LookupContext.new end def link_helper A_LINK end end def new_template(body = " h1 'Hello' ", details = { format: :html }) ActionView::Template.new(body, "hello template", details.fetch(:handler) { GARAHandler }, {:virtual_path => "hello"}.merge!(details)) end def render(locals = {}) output = @template.render(@context, locals) output end def with_doctype(body, alt_doctype = nil) "#{alt_doctype||DEFAULT_DOCTYPE}\n#{body}" end def setup @context = Context.new end test "our handler is registered" do handler = ActionView::Template.registered_template_handler("gara") assert_equal Gara::Template::Handler, handler end test "html generates
Lorum Ipsum
", render end test "other attributes" do @template = new_template("p('Lorum Ipsum', style: 'align: right;')") assert_equal "Lorum Ipsum
", render end test "real document has doctype and newline" do @template = new_template("html { body { h1 \"hello\" } }") assert_equal with_doctype("\n \n