From b7ee6a13d68844e36cb3c3727d68edf089fc8262 Mon Sep 17 00:00:00 2001 From: Davor Ocelic Date: Mon, 5 Feb 2018 16:51:14 +0100 Subject: [PATCH] Add specs for passing custom context to Liquid E.g.: context = Liquid::Context.new context.set "key", "value" render( "/path/to/template.liquid", context) --- spec/kilt/liquid_spec.cr | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/kilt/liquid_spec.cr b/spec/kilt/liquid_spec.cr index f5e0785..f8c4a98 100644 --- a/spec/kilt/liquid_spec.cr +++ b/spec/kilt/liquid_spec.cr @@ -6,6 +6,26 @@ class LiquidView Kilt.file "spec/fixtures/test.liquid" end +class LiquidViewWithCustomContext + # Use of instance variable is not required in user code. It is used here to + # avoid name clash with 'context' variable existing within spec. + def initialize + @context = Liquid::Context.new + @context.set "process", { "pid" => Process.pid } + end + Kilt.file "spec/fixtures/test.liquid", "__kilt_io__", "@context" +end + +it "renders liquid" do + ctx = Liquid::Context.new + ctx.set "process", { "pid" => Process.pid } + Kilt.render("spec/fixtures/test.liquid", ctx).should eq("#{Process.pid}\n") +end + it "works with classes" do LiquidView.new.to_s.should eq("#{Process.pid}\n") end + +it "works with classes and custom context" do + LiquidViewWithCustomContext.new.to_s.should eq("#{Process.pid}\n") +end