mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 03:10:39 -07:00
Add liquid-spec for conformance testing
- Add liquid-spec gem from GitHub to :spec group - Create spec/ruby-liquid.rb adapter for the reference implementation - Add spec job to CI workflow to run liquid-spec tests
This commit is contained in:
@@ -42,6 +42,16 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
RUBYOPT: ${{ matrix.entry.rubyopt }}
|
RUBYOPT: ${{ matrix.entry.rubyopt }}
|
||||||
|
|
||||||
|
spec:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
||||||
|
- uses: ruby/setup-ruby@a25f1e45f0e65a92fcb1e95e8847f78fb0a7197a # v1.273.0
|
||||||
|
with:
|
||||||
|
bundler-cache: true
|
||||||
|
bundler: latest
|
||||||
|
- run: bundle exec liquid-spec run spec/ruby-liquid.rb --no-max-failures
|
||||||
|
|
||||||
memory_profile:
|
memory_profile:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -30,3 +30,7 @@ group :test do
|
|||||||
gem 'rubocop-shopify', '~> 2.18.0', require: false
|
gem 'rubocop-shopify', '~> 2.18.0', require: false
|
||||||
gem 'rubocop-performance', require: false
|
gem 'rubocop-performance', require: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
group :spec do
|
||||||
|
gem 'liquid-spec', github: 'Shopify/liquid-spec'
|
||||||
|
end
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Liquid Spec Adapter for Shopify/liquid (Ruby reference implementation)
|
||||||
|
#
|
||||||
|
# Run with: bundle exec liquid-spec run spec/ruby-liquid.rb
|
||||||
|
|
||||||
|
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
||||||
|
require 'liquid'
|
||||||
|
|
||||||
|
LiquidSpec.configure do |config|
|
||||||
|
# Run core Liquid specs
|
||||||
|
config.features = [:core]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Compile a template string into a Liquid::Template
|
||||||
|
LiquidSpec.compile do |source, options|
|
||||||
|
Liquid::Template.parse(source, **options)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Render a compiled template with the given context
|
||||||
|
LiquidSpec.render do |template, ctx|
|
||||||
|
static_registers = ctx.registers
|
||||||
|
registers = Liquid::Registers.new(static_registers)
|
||||||
|
|
||||||
|
context = Liquid::Context.build(
|
||||||
|
static_environments: ctx.environment,
|
||||||
|
registers: registers,
|
||||||
|
rethrow_errors: ctx.rethrow_errors?
|
||||||
|
)
|
||||||
|
|
||||||
|
context.exception_renderer = ctx.exception_renderer if ctx.exception_renderer
|
||||||
|
|
||||||
|
template.render(context)
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user