Merge pull request #1534 from Shopify/context-test-cleanup

Context test cleanup
This commit is contained in:
Thierry Joyal
2022-03-04 11:31:00 -05:00
committed by GitHub
+9 -11
View File
@@ -24,7 +24,7 @@ class ContextSensitiveDrop < Liquid::Drop
end end
end end
class Category < Liquid::Drop class Category
attr_accessor :name attr_accessor :name
def initialize(name) def initialize(name)
@@ -36,8 +36,9 @@ class Category < Liquid::Drop
end end
end end
class CategoryDrop class CategoryDrop < Liquid::Drop
attr_accessor :category, :context attr_accessor :category, :context
def initialize(category) def initialize(category)
@category = category @category = category
end end
@@ -405,8 +406,9 @@ class ContextTest < Minitest::Test
end end
def test_lambda_is_called_once def test_lambda_is_called_once
@global = 0
@context['callcount'] = proc { @context['callcount'] = proc {
@global ||= 0
@global += 1 @global += 1
@global.to_s @global.to_s
} }
@@ -414,13 +416,12 @@ class ContextTest < Minitest::Test
assert_equal('1', @context['callcount']) assert_equal('1', @context['callcount'])
assert_equal('1', @context['callcount']) assert_equal('1', @context['callcount'])
assert_equal('1', @context['callcount']) assert_equal('1', @context['callcount'])
@global = nil
end end
def test_nested_lambda_is_called_once def test_nested_lambda_is_called_once
@global = 0
@context['callcount'] = { "lambda" => proc { @context['callcount'] = { "lambda" => proc {
@global ||= 0
@global += 1 @global += 1
@global.to_s @global.to_s
} } } }
@@ -428,13 +429,12 @@ class ContextTest < Minitest::Test
assert_equal('1', @context['callcount.lambda']) assert_equal('1', @context['callcount.lambda'])
assert_equal('1', @context['callcount.lambda']) assert_equal('1', @context['callcount.lambda'])
assert_equal('1', @context['callcount.lambda']) assert_equal('1', @context['callcount.lambda'])
@global = nil
end end
def test_lambda_in_array_is_called_once def test_lambda_in_array_is_called_once
@global = 0
@context['callcount'] = [1, 2, proc { @context['callcount'] = [1, 2, proc {
@global ||= 0
@global += 1 @global += 1
@global.to_s @global.to_s
}, 4, 5] }, 4, 5]
@@ -442,8 +442,6 @@ class ContextTest < Minitest::Test
assert_equal('1', @context['callcount[2]']) assert_equal('1', @context['callcount[2]'])
assert_equal('1', @context['callcount[2]']) assert_equal('1', @context['callcount[2]'])
assert_equal('1', @context['callcount[2]']) assert_equal('1', @context['callcount[2]'])
@global = nil
end end
def test_access_to_context_from_proc def test_access_to_context_from_proc