这可能超出了您应该测试的范围,但是如何测试使用缓存的服务方法(即它使用缓存):
def get_payment_methods(country_code, filter=[])
key = "/countries/#{country_code.upcase}/payment_methods"
payment_methods = CACHE.get(key)
unless payment_methods
payment_methods = My::Service.get_payment_methods_for_country(country_code.upcase).first
CACHE.set(key, payment_methods)
end
# ...
end
答案 0 :(得分:1)
您可以创建CACHE
双精度并验证方法的以下内容:
对于RSpec而言,这一切都非常简单