diff --git a/test/integration/assign_test.rb b/test/integration/assign_test.rb index 07d91e76..ba795fbb 100644 --- a/test/integration/assign_test.rb +++ b/test/integration/assign_test.rb @@ -34,14 +34,9 @@ class AssignTest < Minitest::Test end def test_assign_uses_error_mode - with_error_mode(:strict) do - assert_raises(SyntaxError) do - Template.parse("{% assign foo = ('X' | downcase) %}") - end - end - with_error_mode(:lax) do - assert(Template.parse("{% assign foo = ('X' | downcase) %}")) - end + assert_match_syntax_error("Expected dotdot but found pipe in ", + "{% assign foo = ('X' | downcase) %}", error_mode: :strict) + assert_template_result("", "{% assign foo = ('X' | downcase) %}", error_mode: :lax) end def test_expression_with_whitespace_in_square_brackets diff --git a/test/integration/blank_test.rb b/test/integration/blank_test.rb index e3a82c29..b7ca205d 100644 --- a/test/integration/blank_test.rb +++ b/test/integration/blank_test.rb @@ -9,12 +9,6 @@ class FoobarTag < Liquid::Tag end end -class BlankTestFileSystem - def read_template_file(template_path) - template_path - end -end - class BlankTest < Minitest::Test include Liquid N = 10 @@ -95,10 +89,12 @@ class BlankTest < Minitest::Test end def test_include_is_blank - Liquid::Template.file_system = BlankTestFileSystem.new - assert_template_result("foobar" * (N + 1), wrap("{% include 'foobar' %}")) - assert_template_result(" foobar " * (N + 1), wrap("{% include ' foobar ' %}")) - assert_template_result(" " * (N + 1), wrap(" {% include ' ' %} ")) + assert_template_result("foobar" * (N + 1), wrap("{% include 'foobar' %}"), + partials: { 'foobar' => 'foobar' }) + assert_template_result(" foobar " * (N + 1), wrap("{% include ' foobar ' %}"), + partials: { ' foobar ' => ' foobar ' }) + assert_template_result(" " * (N + 1), wrap(" {% include ' ' %} "), + partials: { ' ' => ' ' }) end def test_case_is_blank diff --git a/test/integration/tags/render_tag_test.rb b/test/integration/tags/render_tag_test.rb index 08625525..28e50d1e 100644 --- a/test/integration/tags/render_tag_test.rb +++ b/test/integration/tags/render_tag_test.rb @@ -134,14 +134,17 @@ class RenderTagTest < Minitest::Test end def test_includes_will_not_render_inside_nested_sibling_tags - Liquid::Template.file_system = StubFileSystem.new( - 'foo' => 'bar', - 'nested_render_with_sibling_include' => '{% render "test_include" %}{% include "foo" %}', - 'test_include' => '{% include "foo" %}' + assert_template_result( + "Liquid error (test_include line 1): include usage is not allowed in this context" \ + "Liquid error (nested_render_with_sibling_include line 1): include usage is not allowed in this context", + '{% render "nested_render_with_sibling_include" %}', + partials: { + 'foo' => 'bar', + 'nested_render_with_sibling_include' => '{% render "test_include" %}{% include "foo" %}', + 'test_include' => '{% include "foo" %}', + }, + render_errors: true ) - - output = Liquid::Template.parse('{% render "nested_render_with_sibling_include" %}').render - assert_equal('Liquid error: include usage is not allowed in this contextLiquid error: include usage is not allowed in this context', output) end def test_render_tag_with diff --git a/test/test_helper.rb b/test/test_helper.rb index 3afc8057..de2d534e 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -37,13 +37,21 @@ module Minitest module Assertions include Liquid - def assert_template_result(expected, template, assigns = {}, message: nil) - assert_equal(expected, Template.parse(template, line_numbers: true).render!(assigns), message) + def assert_template_result( + expected, template, assigns = {}, + message: nil, partials: nil, error_mode: nil, render_errors: false + ) + template = Liquid::Template.parse(template, line_numbers: true, error_mode: error_mode&.to_sym) + file_system = StubFileSystem.new(partials) if partials + registers = Liquid::Registers.new(file_system: file_system) + context = Liquid::Context.build(environments: assigns, rethrow_errors: !render_errors, registers: registers) + output = template.render(context) + assert_equal(expected, output, message) end - def assert_match_syntax_error(match, template) + def assert_match_syntax_error(match, template, error_mode: nil) exception = assert_raises(Liquid::SyntaxError) do - Template.parse(template, line_numbers: true).render + Template.parse(template, line_numbers: true, error_mode: error_mode&.to_sym).render end assert_match(match, exception.message) end