require 'test_helper' class HandlerTest < ActiveSupport::TestCase DEFAULT_DOCTYPE = "" A_LINK = %Q(link) class LookupContext def disable_cache yield end def find_template(*args) end attr_accessor :formats end class Context include ActionView::Context include ActionView::Helpers::TagHelper def initialize(*args) @output_buffer = "original" @virtual_path = nil end def lookup_context @lookup_context ||= LookupContext.new end def concat(string) @output_buffer << string end def capture(&block) block.call end def assigns {} end def link_helper A_LINK.html_safe end end def new_template(body = " h1 'Hello' ", details = { format: :html }) ActionView::Template.new(body, "hello template", details.fetch(:handler) { ExpressTemplates::Template::Handler.new }, {: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 controller = Object.new class << controller def view_context_class ; Context ; end end @context = Context.new(nil, {}, controller) end test "our handler is registered" do handler = ActionView::Template.registered_template_handler("et") assert_equal ExpressTemplates::Template::Handler, handler end test "html generates
Lorum Ipsum
\n", render # end test "string in block works" do @template = new_template "h1 { 'foo' } " assert_equal "Lorum Ipsum
\n", render end test "locals work" do @template = new_template "h1 { my_title }" @template.locals = [:my_title] assert_equal "