Skip to content

Commit 608a877

Browse files
committed
Add spec adapter with ActiveSupport for comparison testing
1 parent d321ada commit 608a877

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ end
3434
group :spec do
3535
# Minimum required: 3d1b492 (run `bundle update liquid-spec` to get newer)
3636
gem 'liquid-spec', github: 'Shopify/liquid-spec', ref: '3d1b492dce27cd78b4d5a46ca8cf260ae1349f29'
37+
gem 'activesupport'
3738
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
# Liquid Spec Adapter for Shopify/liquid with ActiveSupport loaded
4+
#
5+
# Run with: bundle exec liquid-spec run spec/ruby_liquid_with_active_support.rb
6+
7+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
8+
require 'active_support/all'
9+
require 'liquid'
10+
11+
LiquidSpec.configure do |config|
12+
# Run core Liquid specs
13+
config.features = [:core]
14+
end
15+
16+
# Compile a template string into a Liquid::Template
17+
LiquidSpec.compile do |source, options|
18+
Liquid::Template.parse(source, **options)
19+
end
20+
21+
# Render a compiled template with the given context
22+
# @param template [Liquid::Template] compiled template
23+
# @param assigns [Hash] environment variables
24+
# @param options [Hash] :registers, :strict_errors, :exception_renderer
25+
LiquidSpec.render do |template, assigns, options|
26+
registers = Liquid::Registers.new(options[:registers] || {})
27+
28+
context = Liquid::Context.build(
29+
static_environments: assigns,
30+
registers: registers,
31+
rethrow_errors: options[:strict_errors],
32+
)
33+
34+
context.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
35+
36+
template.render(context)
37+
end

0 commit comments

Comments
 (0)