Skip to content

Commit 34d7d63

Browse files
authored
Merge pull request #89 from Shopify/cp-bump-5-11
Bump dep to 5.11 and fix broken windows
2 parents f469fd0 + 3f302ed commit 34d7d63

File tree

8 files changed

+1574
-1038
lines changed

8 files changed

+1574
-1038
lines changed

.github/workflows/ruby.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permissions:
88
contents: read
99
jobs:
1010
test:
11-
runs-on: shopify-ubuntu-latest
11+
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
1414
- name: Ruby

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
/spec/reports/
1111
/tmp/
1212
/Gemfile.lock
13+
.claude

CLAUDE.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## What This Project Is
6+
7+
liquid-spec is a test suite for the Liquid templating language. It captures test cases from the reference Shopify/liquid implementation and can verify that other Liquid implementations produce identical output.
8+
9+
## Common Commands
10+
11+
```bash
12+
# Run all tests
13+
bundle exec rake test
14+
15+
# Run a single test file
16+
bundle exec ruby -Ilib:test test/liquid_ruby_test.rb
17+
18+
# Run a specific test method
19+
bundle exec ruby -Ilib:test test/liquid_ruby_test.rb -n test_method_name
20+
21+
# Generate specs from Shopify/liquid (clones repo to tmp/, runs tests, captures output)
22+
bundle exec rake generate
23+
24+
# Generate only liquid_ruby specs
25+
bundle exec rake generate:liquid_ruby
26+
27+
# Generate only standard_filters specs
28+
bundle exec rake generate:standard_filters
29+
```
30+
31+
## Architecture
32+
33+
### Spec Generation Flow
34+
35+
1. `rake generate` clones Shopify/liquid to `tmp/liquid/` at the version matching the liquid gem dependency
36+
2. Patches are injected into the cloned repo's test helper to capture test data during execution
37+
3. Tests run in the cloned repo, writing captured specs to `tmp/liquid-ruby-capture.yml`
38+
4. Captured data is formatted and written to `specs/liquid_ruby/*.yml`
39+
40+
### Key Components
41+
42+
- **`Liquid::Spec::Unit`** (`lib/liquid/spec/unit.rb`): Struct representing a single test case with fields: name, expected, template, environment, filesystem, error_mode, etc.
43+
44+
- **`Liquid::Spec::Source`** (`lib/liquid/spec/source.rb`): Factory for loading specs from different formats (YAML, text, directory-based)
45+
46+
- **`Liquid::Spec::TestGenerator`** (`lib/liquid/spec/test_generator.rb`): Dynamically generates test methods on a test class from spec sources. Groups specs by class name prefix (e.g., `AssignTest#test_foo` creates `AssignTest` subclass).
47+
48+
- **`Liquid::Spec::Adapter`** (`lib/liquid/spec/adapter/`): Adapters render templates. `Default` returns expected values; `LiquidRuby` actually renders with the liquid gem.
49+
50+
- **`Liquid::Spec::Assertions`** (`lib/liquid/spec/assertions.rb`): Module factory that provides `assert_parity_for_spec` comparing expected adapter output against actual adapter output.
51+
52+
### Spec File Format (YAML)
53+
54+
```yaml
55+
- name: TestClass#test_description_hash
56+
template: "{{ foo | upcase }}"
57+
environment:
58+
foo: bar
59+
expected: "BAR"
60+
error_mode: :lax # optional
61+
render_errors: false
62+
filesystem: # optional, for include/render tags
63+
snippet: "content"
64+
```
65+
66+
### Directory Structure
67+
68+
- `specs/liquid_ruby/` - Core Liquid language specs generated from Shopify/liquid tests
69+
- `specs/dawn/` - Shopify Dawn theme section rendering specs
70+
- `lib/liquid/spec/deps/` - Patches applied to Shopify/liquid during spec generation
71+
- `tasks/` - Rake tasks for spec generation

lib/liquid/spec/deps/liquid_ruby.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ def to_s
138138
end
139139
end
140140

141+
class CustomToLiquidDrop < Liquid::Drop
142+
def initialize(value)
143+
@value = value
144+
end
145+
146+
def to_liquid
147+
@value
148+
end
149+
end
150+
151+
class HashWithCustomToS < Hash
152+
def to_s
153+
"kewl"
154+
end
155+
end
156+
157+
class HashWithoutCustomToS < Hash
158+
end
159+
160+
141161
class StringDrop < Liquid::Drop
142162
include Comparable
143163

lib/liquid/spec/deps/shopify_liquid_patch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def assert_template_result(expected, template, assigns = {},
3030
digest << template
3131
digest << data.to_s
3232
digest = digest.hexdigest[0..7]
33-
test_name = "#{class_name}##{name}_#{digest}"
33+
test_name = "#{self.class.name}##{name}_#{digest}"
3434
data = { "name" => test_name }.merge(data).compact
3535
test_data = caller
3636
.select { |line| line.match(%r{liquid-spec/tmp/liquid/test/.*_test\.rb}) }

liquid-spec.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
2525
end
2626
end
2727

28-
spec.add_dependency("liquid", "~> 5.8.7")
28+
spec.add_dependency("liquid", "~> 5.11.0")
2929
spec.add_dependency("super_diff", "~> 0.12.1")
3030
spec.add_dependency("timecop")
3131
spec.add_dependency("tty-box")

specs/liquid_ruby/specs.yml

Lines changed: 1273 additions & 841 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)