test/logster/test_cache.rb in logster-2.4.2 vs test/logster/test_cache.rb in logster-2.5.0

- old
+ new

@@ -1,38 +1,45 @@ +# frozen_string_literal: true + require_relative '../test_helper' require 'logster/cache' class TestCache < Minitest::Test def setup @cache = Logster::Cache.new(5) end def test_cache_works - value = "I should be retured" - prc = Proc.new do - @cache.fetch do + prc = Proc.new do |key, value| + @cache.fetch(key) do value end end - assert_equal(value, prc.call) + value = "I should be retured" + assert_equal(value, prc.call(:key1, value)) cached_value = value value = "I shouldn't be returned" - assert_equal(cached_value, prc.call) + assert_equal(cached_value, prc.call(:key1, value)) + value2 = "value for key2" + assert_equal(value2, prc.call(:key2, value2)) - value = "Now I should be returned again" + value = value2 = "Now I should be returned" Process.stub :clock_gettime, Process.clock_gettime(Process::CLOCK_MONOTONIC) + 6 do - assert_equal(value, prc.call) + assert_equal(value, prc.call(:key1, value)) + assert_equal(value2, prc.call(:key2, value2)) end end def test_cache_can_be_cleared value = "cached" - prc = Proc.new do - @cache.fetch { value } + prc = Proc.new do |key, val| + @cache.fetch(key) { val } end - assert_equal(value, prc.call) + assert_equal(value, prc.call(:key1, value)) + assert_equal("v2", prc.call(:key2, "v2")) value = "new value" - @cache.clear - assert_equal(value, prc.call) + @cache.clear(:key1) + assert_equal(value, prc.call(:key1, value)) + assert_equal("v2", prc.call(:key2, "v2.2")) end end