|
| 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 |
0 commit comments