Skip to content

Commit

Permalink
Support testing by mocking MockRedis#evalsha
Browse files Browse the repository at this point in the history
  • Loading branch information
vu-hoang-kaligo committed Jan 13, 2025
1 parent afbd363 commit 3976fa0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/idempotency/testing/rspec/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'idempotency/cache'

class Idempotency
module Testing
module RSpec
module Helpers
def self.included(_base)
return unless defined?(MockRedis)

MockRedis.class_eval do
def evalsha(sha, keys:, argv:)
return unless sha == Idempotency::Cache::COMPARE_AND_DEL_SCRIPT_SHA

value = argv[0]
cached_value = get(keys[0])

if value == cached_value
del(keys[0])
value
else
cached_value
end
end
end
end
end
end
end
end

0 comments on commit 3976fa0

Please sign in to comment.