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 <[email protected]>
This commit is contained in:
Charles-P. Clermont
2026-01-13 13:06:55 -05:00
co-authored by Claude Opus 4.5
parent 7d90b524ea
commit aa817c4cfd
5 changed files with 18 additions and 21 deletions
-1
View File
@@ -32,7 +32,6 @@ group :test do
end end
group :spec do 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 'liquid-spec', github: 'Shopify/liquid-spec', branch: 'main'
gem 'activesupport', require: false gem 'activesupport', require: false
end end
+5 -6
View File
@@ -13,16 +13,15 @@ LiquidSpec.configure do |config|
end end
# Compile a template string into a Liquid::Template # Compile a template string into a Liquid::Template
LiquidSpec.compile do |_ctx, source, options| LiquidSpec.compile do |ctx, source, options|
Liquid::Template.parse(source, **options) ctx[:template] = Liquid::Template.parse(source, **options)
end end
# Render a compiled template with the given context # Render a compiled template with the given context
# @param ctx [Hash] adapter context (unused) # @param ctx [Hash] adapter context containing :template
# @param template [Liquid::Template] compiled template
# @param assigns [Hash] environment variables # @param assigns [Hash] environment variables
# @param options [Hash] :registers, :strict_errors, :exception_renderer # @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] || {}) registers = Liquid::Registers.new(options[:registers] || {})
context = Liquid::Context.build( 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] context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
template.render(context) ctx[:template].render(context)
end end
+4 -4
View File
@@ -12,14 +12,14 @@ LiquidSpec.configure do |config|
end end
# Compile a template string into a Liquid::Template # Compile a template string into a Liquid::Template
LiquidSpec.compile do |_ctx, source, options| LiquidSpec.compile do |ctx, source, options|
# Force lax mode # Force lax mode
options = options.merge(error_mode: :lax) options = options.merge(error_mode: :lax)
Liquid::Template.parse(source, **options) ctx[:template] = Liquid::Template.parse(source, **options)
end end
# Render a compiled template with the given context # 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] || {}) registers = Liquid::Registers.new(options[:registers] || {})
context = Liquid::Context.build( 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] context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
template.render(context) ctx[:template].render(context)
end end
+5 -6
View File
@@ -14,16 +14,15 @@ LiquidSpec.configure do |config|
end end
# Compile a template string into a Liquid::Template # Compile a template string into a Liquid::Template
LiquidSpec.compile do |_ctx, source, options| LiquidSpec.compile do |ctx, source, options|
Liquid::Template.parse(source, **options) ctx[:template] = Liquid::Template.parse(source, **options)
end end
# Render a compiled template with the given context # Render a compiled template with the given context
# @param ctx [Hash] adapter context (unused) # @param ctx [Hash] adapter context containing :template
# @param template [Liquid::Template] compiled template
# @param assigns [Hash] environment variables # @param assigns [Hash] environment variables
# @param options [Hash] :registers, :strict_errors, :exception_renderer # @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] || {}) registers = Liquid::Registers.new(options[:registers] || {})
context = Liquid::Context.build( 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] context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
template.render(context) ctx[:template].render(context)
end end
+4 -4
View File
@@ -19,14 +19,14 @@ LiquidSpec.configure do |config|
end end
# Compile a template string into a Liquid::Template # Compile a template string into a Liquid::Template
LiquidSpec.compile do |_ctx, source, options| LiquidSpec.compile do |ctx, source, options|
# Force strict mode # Force strict mode
options = { error_mode: :strict }.merge(options) options = { error_mode: :strict }.merge(options)
Liquid::Template.parse(source, **options) ctx[:template] = Liquid::Template.parse(source, **options)
end end
# Render a compiled template with the given context # 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] || {}) registers = Liquid::Registers.new(options[:registers] || {})
context = Liquid::Context.build( 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] context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
template.render(context) ctx[:template].render(context)
end end