From aa817c4cfd8a0ca693698193a4d6d19c1ecbe42e Mon Sep 17 00:00:00 2001 From: "Charles-P. Clermont" Date: Tue, 13 Jan 2026 13:06:55 -0500 Subject: [PATCH] Update liquid-spec adapters for new ctx-based API liquid-spec main changed the adapter API: - compile block now receives (ctx, source, options) and should store the template in ctx[:template] - render block now receives (ctx, assigns, options) and retrieves the template from ctx[:template] Co-Authored-By: Claude Opus 4.5 --- Gemfile | 1 - spec/ruby_liquid.rb | 11 +++++------ spec/ruby_liquid_lax.rb | 8 ++++---- spec/ruby_liquid_with_active_support.rb | 11 +++++------ spec/ruby_liquid_yjit.rb | 8 ++++---- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 4b68a939..a6c44861 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,6 @@ group :test do end group :spec do - # Using feature branch until https://github.com/Shopify/liquid-spec/pull/97 is merged gem 'liquid-spec', github: 'Shopify/liquid-spec', branch: 'main' gem 'activesupport', require: false end diff --git a/spec/ruby_liquid.rb b/spec/ruby_liquid.rb index 8d7f651b..628fbbfe 100644 --- a/spec/ruby_liquid.rb +++ b/spec/ruby_liquid.rb @@ -13,16 +13,15 @@ LiquidSpec.configure do |config| end # Compile a template string into a Liquid::Template -LiquidSpec.compile do |_ctx, source, options| - Liquid::Template.parse(source, **options) +LiquidSpec.compile do |ctx, source, options| + ctx[:template] = Liquid::Template.parse(source, **options) end # Render a compiled template with the given context -# @param ctx [Hash] adapter context (unused) -# @param template [Liquid::Template] compiled template +# @param ctx [Hash] adapter context containing :template # @param assigns [Hash] environment variables # @param options [Hash] :registers, :strict_errors, :exception_renderer -LiquidSpec.render do |_ctx, template, assigns, options| +LiquidSpec.render do |ctx, assigns, options| registers = Liquid::Registers.new(options[:registers] || {}) context = Liquid::Context.build( @@ -33,5 +32,5 @@ LiquidSpec.render do |_ctx, template, assigns, options| context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] - template.render(context) + ctx[:template].render(context) end diff --git a/spec/ruby_liquid_lax.rb b/spec/ruby_liquid_lax.rb index 79f4518c..4681ad41 100644 --- a/spec/ruby_liquid_lax.rb +++ b/spec/ruby_liquid_lax.rb @@ -12,14 +12,14 @@ LiquidSpec.configure do |config| end # Compile a template string into a Liquid::Template -LiquidSpec.compile do |_ctx, source, options| +LiquidSpec.compile do |ctx, source, options| # Force lax mode options = options.merge(error_mode: :lax) - Liquid::Template.parse(source, **options) + ctx[:template] = Liquid::Template.parse(source, **options) end # Render a compiled template with the given context -LiquidSpec.render do |_ctx, template, assigns, options| +LiquidSpec.render do |ctx, assigns, options| registers = Liquid::Registers.new(options[:registers] || {}) context = Liquid::Context.build( @@ -30,5 +30,5 @@ LiquidSpec.render do |_ctx, template, assigns, options| context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] - template.render(context) + ctx[:template].render(context) end diff --git a/spec/ruby_liquid_with_active_support.rb b/spec/ruby_liquid_with_active_support.rb index b577668d..d8b05f76 100644 --- a/spec/ruby_liquid_with_active_support.rb +++ b/spec/ruby_liquid_with_active_support.rb @@ -14,16 +14,15 @@ LiquidSpec.configure do |config| end # Compile a template string into a Liquid::Template -LiquidSpec.compile do |_ctx, source, options| - Liquid::Template.parse(source, **options) +LiquidSpec.compile do |ctx, source, options| + ctx[:template] = Liquid::Template.parse(source, **options) end # Render a compiled template with the given context -# @param ctx [Hash] adapter context (unused) -# @param template [Liquid::Template] compiled template +# @param ctx [Hash] adapter context containing :template # @param assigns [Hash] environment variables # @param options [Hash] :registers, :strict_errors, :exception_renderer -LiquidSpec.render do |_ctx, template, assigns, options| +LiquidSpec.render do |ctx, assigns, options| registers = Liquid::Registers.new(options[:registers] || {}) context = Liquid::Context.build( @@ -34,5 +33,5 @@ LiquidSpec.render do |_ctx, template, assigns, options| context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] - template.render(context) + ctx[:template].render(context) end diff --git a/spec/ruby_liquid_yjit.rb b/spec/ruby_liquid_yjit.rb index d30afb8a..3ff51d1f 100644 --- a/spec/ruby_liquid_yjit.rb +++ b/spec/ruby_liquid_yjit.rb @@ -19,14 +19,14 @@ LiquidSpec.configure do |config| end # Compile a template string into a Liquid::Template -LiquidSpec.compile do |_ctx, source, options| +LiquidSpec.compile do |ctx, source, options| # Force strict mode options = { error_mode: :strict }.merge(options) - Liquid::Template.parse(source, **options) + ctx[:template] = Liquid::Template.parse(source, **options) end # Render a compiled template with the given context -LiquidSpec.render do |_ctx, template, assigns, options| +LiquidSpec.render do |ctx, assigns, options| registers = Liquid::Registers.new(options[:registers] || {}) context = Liquid::Context.build( @@ -37,5 +37,5 @@ LiquidSpec.render do |_ctx, template, assigns, options| context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] - template.render(context) + ctx[:template].render(context) end