From ee4295c889f8896f40caee6fe4ea9bf1ff53ff2c Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Mon, 28 Jul 2014 16:33:42 +0000 Subject: [PATCH 1/5] tests: switch to minitest Ruby 1.9+ uses Minitest as the backend for Test::Unit. As of Minitest 5, the shim has broken some compatibility with Test::Unit::TestCase in some scenarios. Adjusts the test suite to support Minitest 5's syntax. Minitest versions 4 and below do not support the newer Minitest::Test class that arrived in version 5. For that case, use the MiniTest::Unit::TestCase class as a fallback Conflicts: test/integration/tags/for_tag_test.rb test/test_helper.rb --- liquid.gemspec | 1 + test/integration/assign_test.rb | 2 +- test/integration/blank_test.rb | 2 +- test/integration/capture_test.rb | 2 +- test/integration/context_test.rb | 2 +- test/integration/drop_test.rb | 8 +-- test/integration/error_handling_test.rb | 56 ++++++--------- test/integration/filter_test.rb | 4 +- test/integration/hash_ordering_test.rb | 2 +- test/integration/output_test.rb | 2 +- test/integration/parsing_quirks_test.rb | 30 ++++---- test/integration/security_test.rb | 2 +- test/integration/standard_filter_test.rb | 2 +- test/integration/tags/break_tag_test.rb | 2 +- test/integration/tags/continue_tag_test.rb | 2 +- test/integration/tags/for_tag_test.rb | 4 +- test/integration/tags/if_else_tag_test.rb | 32 ++++----- test/integration/tags/include_tag_test.rb | 4 +- test/integration/tags/increment_tag_test.rb | 2 +- test/integration/tags/raw_tag_test.rb | 2 +- test/integration/tags/standard_tag_test.rb | 8 +-- test/integration/tags/statements_test.rb | 2 +- test/integration/tags/table_row_test.rb | 2 +- test/integration/tags/unless_else_tag_test.rb | 2 +- test/integration/template_test.rb | 8 +-- test/integration/variable_test.rb | 2 +- test/test_helper.rb | 71 ++++++++++--------- test/unit/block_unit_test.rb | 7 +- test/unit/condition_unit_test.rb | 2 +- test/unit/context_unit_test.rb | 14 ++-- test/unit/file_system_unit_test.rb | 10 +-- test/unit/i18n_unit_test.rb | 6 +- test/unit/lexer_unit_test.rb | 2 +- test/unit/module_ex_unit_test.rb | 2 +- test/unit/parser_unit_test.rb | 2 +- test/unit/regexp_unit_test.rb | 2 +- test/unit/strainer_unit_test.rb | 2 +- test/unit/tag_unit_test.rb | 2 +- test/unit/tags/case_tag_unit_test.rb | 2 +- test/unit/tags/for_tag_unit_test.rb | 2 +- test/unit/tags/if_tag_unit_test.rb | 2 +- test/unit/template_unit_test.rb | 2 +- test/unit/tokenizer_unit_test.rb | 2 +- test/unit/variable_unit_test.rb | 2 +- 44 files changed, 148 insertions(+), 173 deletions(-) diff --git a/liquid.gemspec b/liquid.gemspec index 0cd2f86..7e90180 100644 --- a/liquid.gemspec +++ b/liquid.gemspec @@ -25,4 +25,5 @@ Gem::Specification.new do |s| s.require_path = "lib" s.add_development_dependency 'rake' + s.add_development_dependency 'minitest' end diff --git a/test/integration/assign_test.rb b/test/integration/assign_test.rb index f4edb9a..e9f5119 100644 --- a/test/integration/assign_test.rb +++ b/test/integration/assign_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class AssignTest < Test::Unit::TestCase +class AssignTest < Minitest::Test include Liquid def test_assigned_variable diff --git a/test/integration/blank_test.rb b/test/integration/blank_test.rb index e70f21c..f2ff9d5 100644 --- a/test/integration/blank_test.rb +++ b/test/integration/blank_test.rb @@ -14,7 +14,7 @@ class BlankTestFileSystem end end -class BlankTest < Test::Unit::TestCase +class BlankTest < Minitest::Test include Liquid N = 10 diff --git a/test/integration/capture_test.rb b/test/integration/capture_test.rb index 0bc7327..1144d0b 100644 --- a/test/integration/capture_test.rb +++ b/test/integration/capture_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class CaptureTest < Test::Unit::TestCase +class CaptureTest < Minitest::Test include Liquid def test_captures_block_content_in_variable diff --git a/test/integration/context_test.rb b/test/integration/context_test.rb index 0f4255a..555a1f2 100644 --- a/test/integration/context_test.rb +++ b/test/integration/context_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ContextTest < Test::Unit::TestCase +class ContextTest < Minitest::Test include Liquid def test_override_global_filter diff --git a/test/integration/drop_test.rb b/test/integration/drop_test.rb index 6edebec..7153435 100644 --- a/test/integration/drop_test.rb +++ b/test/integration/drop_test.rb @@ -100,14 +100,12 @@ class RealEnumerableDrop < Liquid::Drop end end -class DropsTest < Test::Unit::TestCase +class DropsTest < Minitest::Test include Liquid def test_product_drop - assert_nothing_raised do - tpl = Liquid::Template.parse( ' ' ) - tpl.render!('product' => ProductDrop.new) - end + tpl = Liquid::Template.parse( ' ' ) + assert_equal ' ', tpl.render!('product' => ProductDrop.new) end def test_drop_does_only_respond_to_whitelisted_methods diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 192285d..4f25f81 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -19,73 +19,61 @@ class ErrorDrop < Liquid::Drop end -class ErrorHandlingTest < Test::Unit::TestCase +class ErrorHandlingTest < Minitest::Test include Liquid def test_standard_error - assert_nothing_raised do - template = Liquid::Template.parse( ' {{ errors.standard_error }} ' ) - assert_equal ' Liquid error: standard error ', template.render('errors' => ErrorDrop.new) + template = Liquid::Template.parse( ' {{ errors.standard_error }} ' ) + assert_equal ' Liquid error: standard error ', template.render('errors' => ErrorDrop.new) - assert_equal 1, template.errors.size - assert_equal StandardError, template.errors.first.class - end + assert_equal 1, template.errors.size + assert_equal StandardError, template.errors.first.class end def test_syntax + template = Liquid::Template.parse( ' {{ errors.syntax_error }} ' ) + assert_equal ' Liquid syntax error: syntax error ', template.render('errors' => ErrorDrop.new) - assert_nothing_raised do - - template = Liquid::Template.parse( ' {{ errors.syntax_error }} ' ) - assert_equal ' Liquid syntax error: syntax error ', template.render('errors' => ErrorDrop.new) - - assert_equal 1, template.errors.size - assert_equal SyntaxError, template.errors.first.class - - end + assert_equal 1, template.errors.size + assert_equal SyntaxError, template.errors.first.class end def test_argument - assert_nothing_raised do + template = Liquid::Template.parse( ' {{ errors.argument_error }} ' ) + assert_equal ' Liquid error: argument error ', template.render('errors' => ErrorDrop.new) - template = Liquid::Template.parse( ' {{ errors.argument_error }} ' ) - assert_equal ' Liquid error: argument error ', template.render('errors' => ErrorDrop.new) - - assert_equal 1, template.errors.size - assert_equal ArgumentError, template.errors.first.class - end + assert_equal 1, template.errors.size + assert_equal ArgumentError, template.errors.first.class end def test_missing_endtag_parse_time_error - assert_raise(Liquid::SyntaxError) do + assert_raises(Liquid::SyntaxError) do Liquid::Template.parse(' {% for a in b %} ... ') end end def test_unrecognized_operator with_error_mode(:strict) do - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ') end end end def test_lax_unrecognized_operator - assert_nothing_raised do - template = Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ', :error_mode => :lax) - assert_equal ' Liquid error: Unknown operator =! ', template.render - assert_equal 1, template.errors.size - assert_equal Liquid::ArgumentError, template.errors.first.class - end + template = Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ', :error_mode => :lax) + assert_equal ' Liquid error: Unknown operator =! ', template.render + assert_equal 1, template.errors.size + assert_equal Liquid::ArgumentError, template.errors.first.class end def test_strict_error_messages - err = assert_raise(SyntaxError) do + err = assert_raises(SyntaxError) do Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ', :error_mode => :strict) end assert_equal 'Unexpected character = in "1 =! 2"', err.message - err = assert_raise(SyntaxError) do + err = assert_raises(SyntaxError) do Liquid::Template.parse('{{%%%}}', :error_mode => :strict) end assert_equal 'Unexpected character % in "{{%%%}}"', err.message @@ -102,7 +90,7 @@ class ErrorHandlingTest < Test::Unit::TestCase # Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError def test_exceptions_propagate - assert_raise Exception do + assert_raises Exception do template = Liquid::Template.parse( ' {{ errors.exception }} ' ) template.render('errors' => ErrorDrop.new) end diff --git a/test/integration/filter_test.rb b/test/integration/filter_test.rb index b6d1d4b..4789d81 100644 --- a/test/integration/filter_test.rb +++ b/test/integration/filter_test.rb @@ -22,7 +22,7 @@ module SubstituteFilter end end -class FiltersTest < Test::Unit::TestCase +class FiltersTest < Minitest::Test include Liquid def setup @@ -107,7 +107,7 @@ class FiltersTest < Test::Unit::TestCase end end -class FiltersInTemplate < Test::Unit::TestCase +class FiltersInTemplate < Minitest::Test include Liquid def test_local_global diff --git a/test/integration/hash_ordering_test.rb b/test/integration/hash_ordering_test.rb index 3b77709..f100407 100644 --- a/test/integration/hash_ordering_test.rb +++ b/test/integration/hash_ordering_test.rb @@ -12,7 +12,7 @@ module CanadianMoneyFilter end end -class HashOrderingTest < Test::Unit::TestCase +class HashOrderingTest < Minitest::Test include Liquid def test_global_register_order diff --git a/test/integration/output_test.rb b/test/integration/output_test.rb index 37a8745..b7aaf7d 100644 --- a/test/integration/output_test.rb +++ b/test/integration/output_test.rb @@ -27,7 +27,7 @@ module FunnyFilter end -class OutputTest < Test::Unit::TestCase +class OutputTest < Minitest::Test include Liquid def setup diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index add77c3..fd044a6 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ParsingQuirksTest < Test::Unit::TestCase +class ParsingQuirksTest < Minitest::Test include Liquid def test_parsing_css @@ -9,30 +9,28 @@ class ParsingQuirksTest < Test::Unit::TestCase end def test_raise_on_single_close_bracet - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do Template.parse("text {{method} oh nos!") end end def test_raise_on_label_and_no_close_bracets - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do Template.parse("TEST {{ ") end end def test_raise_on_label_and_no_close_bracets_percent - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do Template.parse("TEST {% ") end end def test_error_on_empty_filter - assert_nothing_raised do - Template.parse("{{test}}") - Template.parse("{{|test}}") - end + assert Template.parse("{{test}}") + assert Template.parse("{{|test}}") with_error_mode(:strict) do - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do Template.parse("{{test |a|b|}}") end end @@ -40,7 +38,7 @@ class ParsingQuirksTest < Test::Unit::TestCase def test_meaningless_parens_error with_error_mode(:strict) do - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" Template.parse("{% if #{markup} %} YES {% endif %}") end @@ -49,11 +47,11 @@ class ParsingQuirksTest < Test::Unit::TestCase def test_unexpected_characters_syntax_error with_error_mode(:strict) do - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do markup = "true && false" Template.parse("{% if #{markup} %} YES {% endif %}") end - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do markup = "false || true" Template.parse("{% if #{markup} %} YES {% endif %}") end @@ -61,11 +59,9 @@ class ParsingQuirksTest < Test::Unit::TestCase end def test_no_error_on_lax_empty_filter - assert_nothing_raised do - Template.parse("{{test |a|b|}}", :error_mode => :lax) - Template.parse("{{test}}", :error_mode => :lax) - Template.parse("{{|test|}}", :error_mode => :lax) - end + assert Template.parse("{{test |a|b|}}", :error_mode => :lax) + assert Template.parse("{{test}}", :error_mode => :lax) + assert Template.parse("{{|test|}}", :error_mode => :lax) end def test_meaningless_parens_lax diff --git a/test/integration/security_test.rb b/test/integration/security_test.rb index d512583..427975c 100644 --- a/test/integration/security_test.rb +++ b/test/integration/security_test.rb @@ -6,7 +6,7 @@ module SecurityFilter end end -class SecurityTest < Test::Unit::TestCase +class SecurityTest < Minitest::Test include Liquid def test_no_instance_eval diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index dc223d5..fc6b600 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -41,7 +41,7 @@ class TestEnumerable < Liquid::Drop end end -class StandardFiltersTest < Test::Unit::TestCase +class StandardFiltersTest < Minitest::Test include Liquid def setup diff --git a/test/integration/tags/break_tag_test.rb b/test/integration/tags/break_tag_test.rb index cbe3095..1dd657b 100644 --- a/test/integration/tags/break_tag_test.rb +++ b/test/integration/tags/break_tag_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class BreakTagTest < Test::Unit::TestCase +class BreakTagTest < Minitest::Test include Liquid # tests that no weird errors are raised if break is called outside of a diff --git a/test/integration/tags/continue_tag_test.rb b/test/integration/tags/continue_tag_test.rb index 5825a23..4386cac 100644 --- a/test/integration/tags/continue_tag_test.rb +++ b/test/integration/tags/continue_tag_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ContinueTagTest < Test::Unit::TestCase +class ContinueTagTest < Minitest::Test include Liquid # tests that no weird errors are raised if continue is called outside of a diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 120f7fa..8ccc056 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -6,7 +6,7 @@ class ThingWithValue < Liquid::Drop end end -class ForTagTest < Test::Unit::TestCase +class ForTagTest < Minitest::Test include Liquid def test_for @@ -303,7 +303,7 @@ HERE end def test_bad_variable_naming_in_for_loop - assert_raise(Liquid::SyntaxError) do + assert_raises(Liquid::SyntaxError) do Liquid::Template.parse('{% for a/b in x %}{% endfor %}') end end diff --git a/test/integration/tags/if_else_tag_test.rb b/test/integration/tags/if_else_tag_test.rb index afd12bd..53e2837 100644 --- a/test/integration/tags/if_else_tag_test.rb +++ b/test/integration/tags/if_else_tag_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class IfElseTagTest < Test::Unit::TestCase +class IfElseTagTest < Minitest::Test include Liquid def test_if @@ -37,25 +37,19 @@ class IfElseTagTest < Test::Unit::TestCase end def test_comparison_of_strings_containing_and_or_or - assert_nothing_raised do - awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar" - assigns = {'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true} - assert_template_result(' YES ',"{% if #{awful_markup} %} YES {% endif %}", assigns) - end + awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar" + assigns = {'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true} + assert_template_result(' YES ',"{% if #{awful_markup} %} YES {% endif %}", assigns) end def test_comparison_of_expressions_starting_with_and_or_or assigns = {'order' => {'items_count' => 0}, 'android' => {'name' => 'Roy'}} - assert_nothing_raised do - assert_template_result( "YES", - "{% if android.name == 'Roy' %}YES{% endif %}", - assigns) - end - assert_nothing_raised do - assert_template_result( "YES", - "{% if order.items_count == 0 %}YES{% endif %}", - assigns) - end + assert_template_result( "YES", + "{% if android.name == 'Roy' %}YES{% endif %}", + assigns) + assert_template_result( "YES", + "{% if order.items_count == 0 %}YES{% endif %}", + assigns) end def test_if_and @@ -135,11 +129,11 @@ class IfElseTagTest < Test::Unit::TestCase end def test_syntax_error_no_variable - assert_raise(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')} + assert_raises(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')} end def test_syntax_error_no_expression - assert_raise(SyntaxError) { assert_template_result('', '{% if %}') } + assert_raises(SyntaxError) { assert_template_result('', '{% if %}') } end def test_if_with_custom_condition @@ -159,7 +153,7 @@ class IfElseTagTest < Test::Unit::TestCase end def test_operators_are_whitelisted - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do assert_template_result('', %({% if 1 or throw or or 1 %}yes{% endif %})) end end diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index e4fab37..05e84bb 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -65,7 +65,7 @@ class CustomInclude < Liquid::Tag end end -class IncludeTagTest < Test::Unit::TestCase +class IncludeTagTest < Minitest::Test include Liquid def setup @@ -132,7 +132,7 @@ class IncludeTagTest < Test::Unit::TestCase Liquid::Template.file_system = infinite_file_system.new - assert_raise(Liquid::StackLevelError) do + assert_raises(Liquid::StackLevelError) do Template.parse("{% include 'loop' %}").render! end diff --git a/test/integration/tags/increment_tag_test.rb b/test/integration/tags/increment_tag_test.rb index 6c673ff..a09a041 100644 --- a/test/integration/tags/increment_tag_test.rb +++ b/test/integration/tags/increment_tag_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class IncrementTagTest < Test::Unit::TestCase +class IncrementTagTest < Minitest::Test include Liquid def test_inc diff --git a/test/integration/tags/raw_tag_test.rb b/test/integration/tags/raw_tag_test.rb index 1583ef0..167474c 100644 --- a/test/integration/tags/raw_tag_test.rb +++ b/test/integration/tags/raw_tag_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RawTagTest < Test::Unit::TestCase +class RawTagTest < Minitest::Test include Liquid def test_tag_in_raw diff --git a/test/integration/tags/standard_tag_test.rb b/test/integration/tags/standard_tag_test.rb index acb9970..c8221b6 100644 --- a/test/integration/tags/standard_tag_test.rb +++ b/test/integration/tags/standard_tag_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class StandardTagTest < Test::Unit::TestCase +class StandardTagTest < Minitest::Test include Liquid def test_no_transform @@ -66,7 +66,7 @@ class StandardTagTest < Test::Unit::TestCase end def test_capture_detects_bad_syntax - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do assert_template_result('content foo content foo ', '{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}', {'var' => 'content' }) @@ -229,11 +229,11 @@ class StandardTagTest < Test::Unit::TestCase end def test_case_detects_bad_syntax - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do assert_template_result('', '{% case false %}{% when %}true{% endcase %}', {}) end - assert_raise(SyntaxError) do + assert_raises(SyntaxError) do assert_template_result('', '{% case false %}{% huh %}true{% endcase %}', {}) end diff --git a/test/integration/tags/statements_test.rb b/test/integration/tags/statements_test.rb index 63b004e..a7b3bad 100644 --- a/test/integration/tags/statements_test.rb +++ b/test/integration/tags/statements_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class StatementsTest < Test::Unit::TestCase +class StatementsTest < Minitest::Test include Liquid def test_true_eql_true diff --git a/test/integration/tags/table_row_test.rb b/test/integration/tags/table_row_test.rb index 79d621b..3751963 100644 --- a/test/integration/tags/table_row_test.rb +++ b/test/integration/tags/table_row_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class TableRowTest < Test::Unit::TestCase +class TableRowTest < Minitest::Test include Liquid class ArrayDrop < Liquid::Drop diff --git a/test/integration/tags/unless_else_tag_test.rb b/test/integration/tags/unless_else_tag_test.rb index 352b6d6..ba147cf 100644 --- a/test/integration/tags/unless_else_tag_test.rb +++ b/test/integration/tags/unless_else_tag_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class UnlessElseTagTest < Test::Unit::TestCase +class UnlessElseTagTest < Minitest::Test include Liquid def test_unless diff --git a/test/integration/template_test.rb b/test/integration/template_test.rb index 20adf8c..7fdd85f 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -28,7 +28,7 @@ class ErroneousDrop < Liquid::Drop end end -class TemplateTest < Test::Unit::TestCase +class TemplateTest < Minitest::Test include Liquid def test_instance_assigns_persist_on_same_template_object_between_parses @@ -93,7 +93,7 @@ class TemplateTest < Test::Unit::TestCase assert t.resource_limits[:reached] t.resource_limits = { :render_length_limit => 10 } assert_equal "0123456789", t.render!() - assert_not_nil t.resource_limits[:render_length_current] + refute_nil t.resource_limits[:render_length_current] end def test_resource_limits_render_score @@ -107,7 +107,7 @@ class TemplateTest < Test::Unit::TestCase assert t.resource_limits[:reached] t.resource_limits = { :render_score_limit => 200 } assert_equal (" foo " * 100), t.render!() - assert_not_nil t.resource_limits[:render_score_current] + refute_nil t.resource_limits[:render_score_current] end def test_resource_limits_assign_score @@ -117,7 +117,7 @@ class TemplateTest < Test::Unit::TestCase assert t.resource_limits[:reached] t.resource_limits = { :assign_score_limit => 2 } assert_equal "", t.render!() - assert_not_nil t.resource_limits[:assign_score_current] + refute_nil t.resource_limits[:assign_score_current] end def test_resource_limits_aborts_rendering_after_first_error diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index 4bc2ba9..37456cc 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class VariableTest < Test::Unit::TestCase +class VariableTest < Minitest::Test include Liquid def test_simple_variable diff --git a/test/test_helper.rb b/test/test_helper.rb index 3f02d42..d5bfe9e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby -require 'test/unit' -require 'test/unit/assertions' +require 'minitest/autorun' require 'spy/integration' $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')) @@ -14,41 +13,45 @@ if env_mode = ENV['LIQUID_PARSER_MODE'] end Liquid::Template.error_mode = mode +if Minitest.const_defined?('Test') + # We're on Minitest 5+. Nothing to do here. +else + # Minitest 4 doesn't have Minitest::Test yet. + Minitest::Test = MiniTest::Unit::TestCase +end -module Test - module Unit - class TestCase - def fixture(name) - File.join(File.expand_path(File.dirname(__FILE__)), "fixtures", name) - end +module Minitest + class Test + def fixture(name) + File.join(File.expand_path(File.dirname(__FILE__)), "fixtures", name) + end + end + + module Assertions + include Liquid + + def assert_template_result(expected, template, assigns = {}, message = nil) + assert_equal expected, Template.parse(template).render!(assigns) end - module Assertions - include Liquid + def assert_template_result_matches(expected, template, assigns = {}, message = nil) + return assert_template_result(expected, template, assigns, message) unless expected.is_a? Regexp - def assert_template_result(expected, template, assigns = {}, message = nil) - assert_equal expected, Template.parse(template).render!(assigns) - end + assert_match expected, Template.parse(template).render!(assigns) + end - def assert_template_result_matches(expected, template, assigns = {}, message = nil) - return assert_template_result(expected, template, assigns, message) unless expected.is_a? Regexp + def assert_match_syntax_error(match, template, registers = {}) + exception = assert_raises(Liquid::SyntaxError) { + Template.parse(template).render(assigns) + } + assert_match match, exception.message + end - assert_match expected, Template.parse(template).render!(assigns) - end - - def assert_match_syntax_error(match, template, registers = {}) - exception = assert_raise(Liquid::SyntaxError) { - Template.parse(template).render(assigns) - } - assert_match match, exception.message - end - - def with_error_mode(mode) - old_mode = Liquid::Template.error_mode - Liquid::Template.error_mode = mode - yield - Liquid::Template.error_mode = old_mode - end - end # Assertions - end # Unit -end # Test + def with_error_mode(mode) + old_mode = Liquid::Template.error_mode + Liquid::Template.error_mode = mode + yield + Liquid::Template.error_mode = old_mode + end + end +end diff --git a/test/unit/block_unit_test.rb b/test/unit/block_unit_test.rb index ca46474..09bbbea 100644 --- a/test/unit/block_unit_test.rb +++ b/test/unit/block_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class BlockUnitTest < Test::Unit::TestCase +class BlockUnitTest < Minitest::Test include Liquid def test_blankspace @@ -45,10 +45,7 @@ class BlockUnitTest < Test::Unit::TestCase def test_with_custom_tag Liquid::Template.register_tag("testtag", Block) - - assert_nothing_thrown do - template = Liquid::Template.parse( "{% testtag %} {% endtesttag %}") - end + assert Liquid::Template.parse( "{% testtag %} {% endtesttag %}") end private diff --git a/test/unit/condition_unit_test.rb b/test/unit/condition_unit_test.rb index e5bea3d..c0ce140 100644 --- a/test/unit/condition_unit_test.rb +++ b/test/unit/condition_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ConditionUnitTest < Test::Unit::TestCase +class ConditionUnitTest < Minitest::Test include Liquid def test_basic_condition diff --git a/test/unit/context_unit_test.rb b/test/unit/context_unit_test.rb index 1b8d717..848f66f 100644 --- a/test/unit/context_unit_test.rb +++ b/test/unit/context_unit_test.rb @@ -63,7 +63,7 @@ class ArrayLike end end -class ContextUnitTest < Test::Unit::TestCase +class ContextUnitTest < Minitest::Test include Liquid def setup @@ -107,16 +107,14 @@ class ContextUnitTest < Test::Unit::TestCase end def test_scoping - assert_nothing_raised do - @context.push + @context.push + @context.pop + + assert_raises(Liquid::ContextError) do @context.pop end - assert_raise(Liquid::ContextError) do - @context.pop - end - - assert_raise(Liquid::ContextError) do + assert_raises(Liquid::ContextError) do @context.push @context.pop @context.pop diff --git a/test/unit/file_system_unit_test.rb b/test/unit/file_system_unit_test.rb index 31bccb2..02e3638 100644 --- a/test/unit/file_system_unit_test.rb +++ b/test/unit/file_system_unit_test.rb @@ -1,10 +1,10 @@ require 'test_helper' -class FileSystemUnitTest < Test::Unit::TestCase +class FileSystemUnitTest < Minitest::Test include Liquid def test_default - assert_raise(FileSystemError) do + assert_raises(FileSystemError) do BlankFileSystem.new.read_template_file("dummy", {'dummy'=>'smarty'}) end end @@ -14,15 +14,15 @@ class FileSystemUnitTest < Test::Unit::TestCase assert_equal "/some/path/_mypartial.liquid" , file_system.full_path("mypartial") assert_equal "/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial") - assert_raise(FileSystemError) do + assert_raises(FileSystemError) do file_system.full_path("../dir/mypartial") end - assert_raise(FileSystemError) do + assert_raises(FileSystemError) do file_system.full_path("/dir/../../dir/mypartial") end - assert_raise(FileSystemError) do + assert_raises(FileSystemError) do file_system.full_path("/etc/passwd") end end diff --git a/test/unit/i18n_unit_test.rb b/test/unit/i18n_unit_test.rb index cc05400..389ea56 100644 --- a/test/unit/i18n_unit_test.rb +++ b/test/unit/i18n_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class I18nUnitTest < Test::Unit::TestCase +class I18nUnitTest < Minitest::Test include Liquid def setup @@ -20,13 +20,13 @@ class I18nUnitTest < Test::Unit::TestCase end # def test_raises_translation_error_on_undefined_interpolation_key - # assert_raise I18n::TranslationError do + # assert_raises I18n::TranslationError do # @i18n.translate("whatever", :oopstypos => "yes") # end # end def test_raises_unknown_translation - assert_raise I18n::TranslationError do + assert_raises I18n::TranslationError do @i18n.translate("doesnt_exist") end end diff --git a/test/unit/lexer_unit_test.rb b/test/unit/lexer_unit_test.rb index 7ff2bb1..96dadee 100644 --- a/test/unit/lexer_unit_test.rb +++ b/test/unit/lexer_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class LexerUnitTest < Test::Unit::TestCase +class LexerUnitTest < Minitest::Test include Liquid def test_strings diff --git a/test/unit/module_ex_unit_test.rb b/test/unit/module_ex_unit_test.rb index 5cefb7f..8e12653 100644 --- a/test/unit/module_ex_unit_test.rb +++ b/test/unit/module_ex_unit_test.rb @@ -36,7 +36,7 @@ class TestClassC::LiquidDropClass end end -class ModuleExUnitTest < Test::Unit::TestCase +class ModuleExUnitTest < Minitest::Test include Liquid def setup diff --git a/test/unit/parser_unit_test.rb b/test/unit/parser_unit_test.rb index b10a176..d483367 100644 --- a/test/unit/parser_unit_test.rb +++ b/test/unit/parser_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ParserUnitTest < Test::Unit::TestCase +class ParserUnitTest < Minitest::Test include Liquid def test_consume diff --git a/test/unit/regexp_unit_test.rb b/test/unit/regexp_unit_test.rb index 808c28d..baabae3 100644 --- a/test/unit/regexp_unit_test.rb +++ b/test/unit/regexp_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegexpUnitTest < Test::Unit::TestCase +class RegexpUnitTest < Minitest::Test include Liquid def test_empty diff --git a/test/unit/strainer_unit_test.rb b/test/unit/strainer_unit_test.rb index aa0296c..68099b3 100644 --- a/test/unit/strainer_unit_test.rb +++ b/test/unit/strainer_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class StrainerUnitTest < Test::Unit::TestCase +class StrainerUnitTest < Minitest::Test include Liquid module AccessScopeFilters diff --git a/test/unit/tag_unit_test.rb b/test/unit/tag_unit_test.rb index e9111aa..c5c2a46 100644 --- a/test/unit/tag_unit_test.rb +++ b/test/unit/tag_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class TagUnitTest < Test::Unit::TestCase +class TagUnitTest < Minitest::Test include Liquid def test_tag diff --git a/test/unit/tags/case_tag_unit_test.rb b/test/unit/tags/case_tag_unit_test.rb index ddb8d83..3c1be2c 100644 --- a/test/unit/tags/case_tag_unit_test.rb +++ b/test/unit/tags/case_tag_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class CaseTagUnitTest < Test::Unit::TestCase +class CaseTagUnitTest < Minitest::Test include Liquid def test_case_nodelist diff --git a/test/unit/tags/for_tag_unit_test.rb b/test/unit/tags/for_tag_unit_test.rb index 07ac184..17f88ce 100644 --- a/test/unit/tags/for_tag_unit_test.rb +++ b/test/unit/tags/for_tag_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ForTagUnitTest < Test::Unit::TestCase +class ForTagUnitTest < Minitest::Test def test_for_nodelist template = Liquid::Template.parse('{% for item in items %}FOR{% endfor %}') assert_equal ['FOR'], template.root.nodelist[0].nodelist diff --git a/test/unit/tags/if_tag_unit_test.rb b/test/unit/tags/if_tag_unit_test.rb index 209e3c2..17f826c 100644 --- a/test/unit/tags/if_tag_unit_test.rb +++ b/test/unit/tags/if_tag_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class IfTagUnitTest < Test::Unit::TestCase +class IfTagUnitTest < Minitest::Test def test_if_nodelist template = Liquid::Template.parse('{% if true %}IF{% else %}ELSE{% endif %}') assert_equal ['IF', 'ELSE'], template.root.nodelist[0].nodelist diff --git a/test/unit/template_unit_test.rb b/test/unit/template_unit_test.rb index 41e024d..c50b067 100644 --- a/test/unit/template_unit_test.rb +++ b/test/unit/template_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class TemplateUnitTest < Test::Unit::TestCase +class TemplateUnitTest < Minitest::Test include Liquid def test_sets_default_localization_in_document diff --git a/test/unit/tokenizer_unit_test.rb b/test/unit/tokenizer_unit_test.rb index e8f4a0d..e1146d8 100644 --- a/test/unit/tokenizer_unit_test.rb +++ b/test/unit/tokenizer_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class TokenizerTest < Test::Unit::TestCase +class TokenizerTest < Minitest::Test def test_tokenize_strings assert_equal [' '], tokenize(' ') assert_equal ['hello world'], tokenize('hello world') diff --git a/test/unit/variable_unit_test.rb b/test/unit/variable_unit_test.rb index 4c1cfbc..b46aa19 100644 --- a/test/unit/variable_unit_test.rb +++ b/test/unit/variable_unit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class VariableUnitTest < Test::Unit::TestCase +class VariableUnitTest < Minitest::Test include Liquid def test_variable From deba039d6df17524525518d61637ab8f77a34d10 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Sat, 17 May 2014 17:01:52 -0600 Subject: [PATCH 2/5] tests: reset "contains" op during IfElseTagTest Two tests in IfElseTagTest each set a custom operator function for the "contains" comparison operator. The problem is that IfElseTagTest was clobbering the original operator in Liquid and leaving it in an altered state. As an example, ConditionUnitTest's test_contains_works_on_arrays relies on the specific behavior of the "contains" operator, and its test_contains_works_on_arrays was failing. The problem was present when both test classes were require'd inside a single ruby process. One example is "rake test", which runs "require" on every test file. Another basic example is the following command: ruby -Itest -e "require 'integration/tags/if_else_tag_test.rb'; require 'unit/condition_unit_test.rb'" This would cause test_contains_works_on_arrays to fail. Update IfElseTagTest to avoid clobbering the "contains" operator. With this change, ConditionUnitTest's test_contains_works_on_arrays now passes. --- test/integration/tags/if_else_tag_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/integration/tags/if_else_tag_test.rb b/test/integration/tags/if_else_tag_test.rb index 53e2837..0b7ee0e 100644 --- a/test/integration/tags/if_else_tag_test.rb +++ b/test/integration/tags/if_else_tag_test.rb @@ -137,19 +137,23 @@ class IfElseTagTest < Minitest::Test end def test_if_with_custom_condition + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %})) assert_template_result('no', %({% if 'bob' contains 'f' %}yes{% else %}no{% endif %})) ensure - Condition.operators.delete 'contains' + Condition.operators['contains'] = original_op end def test_operators_are_ignored_unless_isolated + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', %({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %})) + ensure + Condition.operators['contains'] = original_op end def test_operators_are_whitelisted From 3e3a415457dd4422e1207c910dde800744bbf56d Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Sat, 17 May 2014 22:28:47 -0600 Subject: [PATCH 3/5] tests: fix whitespace in hash_ordering_test Indent two spaces, not one. --- test/integration/hash_ordering_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/hash_ordering_test.rb b/test/integration/hash_ordering_test.rb index f100407..cbd350d 100644 --- a/test/integration/hash_ordering_test.rb +++ b/test/integration/hash_ordering_test.rb @@ -15,11 +15,11 @@ end class HashOrderingTest < Minitest::Test include Liquid - def test_global_register_order + def test_global_register_order Template.register_filter(MoneyFilter) Template.register_filter(CanadianMoneyFilter) assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, nil) - end - + end + end From 57d5426eeda04a4fd21c328176fca65cd2e9f8c7 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Sat, 17 May 2014 22:26:36 -0600 Subject: [PATCH 4/5] tests: reset Strainer's filters after modification Three tests in the test suite use the Liquid::Template.register_filter function to register custom filters with Liquid::Strainer. The problem is that these register_filter calls leave the Liquid::Strainer object in an altered state. As an example, the FiltersTest's test_local_filter relies on the default behavior of Liquid::Strainer operator, and the test was failing if register_function had been called earlier. The same thing was happening with FiltersInTemplate's test_local_global. The problem was present when the Filters test classes were loaded inside a single ruby process that also loaded HashOrderingTest. One example is "rake test", which runs "require" on every test file. Another basic example is the following command: ruby -Itest -e "require 'integration/hash_ordering_test'; require 'integration/filter_test'" Update the tests to always reset Liquid::Strainer's filters back to the default list of filters. With this change, FiltersTest and FiltersInTemplate now pass. --- test/integration/context_test.rb | 3 +++ test/integration/filter_test.rb | 3 +++ test/integration/hash_ordering_test.rb | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/integration/context_test.rb b/test/integration/context_test.rb index 555a1f2..942a506 100644 --- a/test/integration/context_test.rb +++ b/test/integration/context_test.rb @@ -16,9 +16,12 @@ class ContextTest < Minitest::Test end end + original_filters = Array.new(Strainer.class_eval('@@filters')) Template.register_filter(global) assert_equal 'Global test', Template.parse("{{'test' | notice }}").render! assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, :filters => [local]) + ensure + Strainer.class_eval('@@filters = ' + original_filters.to_s) end def test_has_key_will_not_add_an_error_for_missing_keys diff --git a/test/integration/filter_test.rb b/test/integration/filter_test.rb index 4789d81..f214f94 100644 --- a/test/integration/filter_test.rb +++ b/test/integration/filter_test.rb @@ -111,11 +111,14 @@ class FiltersInTemplate < Minitest::Test include Liquid def test_local_global + original_filters = Array.new(Strainer.class_eval('@@filters')) Template.register_filter(MoneyFilter) assert_equal " 1000$ ", Template.parse("{{1000 | money}}").render!(nil, nil) assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render!(nil, :filters => CanadianMoneyFilter) assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render!(nil, :filters => [CanadianMoneyFilter]) + ensure + Strainer.class_eval('@@filters = ' + original_filters.to_s) end def test_local_filter_with_deprecated_syntax diff --git a/test/integration/hash_ordering_test.rb b/test/integration/hash_ordering_test.rb index cbd350d..51b095a 100644 --- a/test/integration/hash_ordering_test.rb +++ b/test/integration/hash_ordering_test.rb @@ -16,10 +16,13 @@ class HashOrderingTest < Minitest::Test include Liquid def test_global_register_order + original_filters = Array.new(Strainer.class_eval('@@filters')) Template.register_filter(MoneyFilter) Template.register_filter(CanadianMoneyFilter) assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, nil) + ensure + Strainer.class_eval('@@filters = ' + original_filters.to_s) end - + end From a2f0f2547da26b9ca1f6b09cdf18cfff19681114 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Mon, 28 Jul 2014 16:32:09 +0000 Subject: [PATCH 5/5] with_global_filter test helper --- test/integration/context_test.rb | 10 ++++------ test/integration/drop_test.rb | 2 +- test/integration/filter_test.rb | 13 +++++-------- test/integration/hash_ordering_test.rb | 11 +++-------- test/integration/parsing_quirks_test.rb | 2 +- test/test_helper.rb | 11 +++++++++++ 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/test/integration/context_test.rb b/test/integration/context_test.rb index 942a506..d537aa2 100644 --- a/test/integration/context_test.rb +++ b/test/integration/context_test.rb @@ -16,12 +16,10 @@ class ContextTest < Minitest::Test end end - original_filters = Array.new(Strainer.class_eval('@@filters')) - Template.register_filter(global) - assert_equal 'Global test', Template.parse("{{'test' | notice }}").render! - assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, :filters => [local]) - ensure - Strainer.class_eval('@@filters = ' + original_filters.to_s) + with_global_filter(global) do + assert_equal 'Global test', Template.parse("{{'test' | notice }}").render! + assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, :filters => [local]) + end end def test_has_key_will_not_add_an_error_for_missing_keys diff --git a/test/integration/drop_test.rb b/test/integration/drop_test.rb index 7153435..7290298 100644 --- a/test/integration/drop_test.rb +++ b/test/integration/drop_test.rb @@ -104,7 +104,7 @@ class DropsTest < Minitest::Test include Liquid def test_product_drop - tpl = Liquid::Template.parse( ' ' ) + tpl = Liquid::Template.parse(' ') assert_equal ' ', tpl.render!('product' => ProductDrop.new) end diff --git a/test/integration/filter_test.rb b/test/integration/filter_test.rb index f214f94..d84458b 100644 --- a/test/integration/filter_test.rb +++ b/test/integration/filter_test.rb @@ -111,14 +111,11 @@ class FiltersInTemplate < Minitest::Test include Liquid def test_local_global - original_filters = Array.new(Strainer.class_eval('@@filters')) - Template.register_filter(MoneyFilter) - - assert_equal " 1000$ ", Template.parse("{{1000 | money}}").render!(nil, nil) - assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render!(nil, :filters => CanadianMoneyFilter) - assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render!(nil, :filters => [CanadianMoneyFilter]) - ensure - Strainer.class_eval('@@filters = ' + original_filters.to_s) + with_global_filter(MoneyFilter) do + assert_equal " 1000$ ", Template.parse("{{1000 | money}}").render!(nil, nil) + assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render!(nil, :filters => CanadianMoneyFilter) + assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render!(nil, :filters => [CanadianMoneyFilter]) + end end def test_local_filter_with_deprecated_syntax diff --git a/test/integration/hash_ordering_test.rb b/test/integration/hash_ordering_test.rb index 51b095a..588e1c1 100644 --- a/test/integration/hash_ordering_test.rb +++ b/test/integration/hash_ordering_test.rb @@ -16,13 +16,8 @@ class HashOrderingTest < Minitest::Test include Liquid def test_global_register_order - original_filters = Array.new(Strainer.class_eval('@@filters')) - Template.register_filter(MoneyFilter) - Template.register_filter(CanadianMoneyFilter) - - assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, nil) - ensure - Strainer.class_eval('@@filters = ' + original_filters.to_s) + with_global_filter(MoneyFilter, CanadianMoneyFilter) do + assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, nil) + end end - end diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index fd044a6..0701530 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -82,7 +82,7 @@ class ParsingQuirksTest < Minitest::Test end def test_raise_on_invalid_tag_delimiter - assert_raise(Liquid::SyntaxError) do + assert_raises(Liquid::SyntaxError) do Template.new.parse('{% end %}') end end diff --git a/test/test_helper.rb b/test/test_helper.rb index d5bfe9e..d513f65 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -47,10 +47,21 @@ module Minitest assert_match match, exception.message end + def with_global_filter(*globals) + original_filters = Array.new(Liquid::Strainer.class_variable_get(:@@filters)) + globals.each do |global| + Liquid::Template.register_filter(global) + end + yield + ensure + Liquid::Strainer.class_variable_set(:@@filters, original_filters) + end + def with_error_mode(mode) old_mode = Liquid::Template.error_mode Liquid::Template.error_mode = mode yield + ensure Liquid::Template.error_mode = old_mode end end