Sha256: 1f7408a4aec52f30b296beec9ec5068f627b6e55534db2e633e9fce47ee042c7
Contents?: true
Size: 1.12 KB
Versions: 21
Compression:
Stored size: 1.12 KB
Contents
require "helper" class TestCssCache < Nokogiri::TestCase def setup super @css = "a1 > b2 > c3" @parse_result = Nokogiri::CSS.parse(@css) @to_xpath_result = @parse_result.map(&:to_xpath) Nokogiri::CSS::Parser.class_eval do class << @cache alias :old_bracket :[] attr_reader :count def [](key) @count ||= 0 @count += 1 old_bracket(key) end end end assert Nokogiri::CSS::Parser.cache_on? end def teardown Nokogiri::CSS::Parser.clear_cache Nokogiri::CSS::Parser.set_cache true end [ false, true ].each do |cache_setting| define_method "test_css_cache_#{cache_setting ? "true" : "false"}" do Nokogiri::CSS::Parser.set_cache cache_setting Nokogiri::CSS.xpath_for(@css) Nokogiri::CSS.xpath_for(@css) Nokogiri::CSS::Parser.new.xpath_for(@css) Nokogiri::CSS::Parser.new.xpath_for(@css) if cache_setting assert_equal(4, Nokogiri::CSS::Parser.class_eval { @cache.count }) else assert_nil(Nokogiri::CSS::Parser.class_eval { @cache.count }) end end end end
Version data entries
21 entries across 18 versions & 3 rubygems