From deba039d6df17524525518d61637ab8f77a34d10 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Sat, 17 May 2014 17:01:52 -0600 Subject: [PATCH] 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 53e28375..0b7ee0e9 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