spec/ollama/documents/memory_cache_spec.rb in ollama-ruby-0.3.2 vs spec/ollama/documents/memory_cache_spec.rb in ollama-ruby-0.4.0
- old
+ new
@@ -1,63 +1,63 @@
require 'spec_helper'
RSpec.describe Ollama::Documents::MemoryCache do
- let :memory_cache do
+ let :cache do
described_class.new prefix: 'test-'
end
it 'can be instantiated' do
- expect(memory_cache).to be_a described_class
+ expect(cache).to be_a described_class
end
it 'can get/set a key' do
key, value = 'foo', { test: true }
expect {
- memory_cache[key] = value
+ cache[key] = value
}.to change {
- memory_cache[key]
+ cache[key]
}.from(nil).to(value)
end
it 'can determine if key exists' do
key, value = 'foo', { test: true }
expect {
- memory_cache[key] = value
+ cache[key] = value
}.to change {
- memory_cache.key?(key)
+ cache.key?(key)
}.from(false).to(true)
end
it 'can delete' do
key, value = 'foo', { test: true }
- memory_cache[key] = value
+ cache[key] = value
expect {
- memory_cache.delete(key)
+ cache.delete(key)
}.to change {
- memory_cache.key?(key)
+ cache.key?(key)
}.from(true).to(false)
end
it 'returns size' do
key, value = 'foo', { test: true }
expect {
- memory_cache[key] = value
+ cache[key] = value
}.to change {
- memory_cache.size
+ cache.size
}.from(0).to(1)
end
it 'can clear' do
key, value = 'foo', { test: true }
- memory_cache[key] = value
+ cache[key] = value
expect {
- expect(memory_cache.clear).to eq memory_cache
+ expect(cache.clear).to eq cache
}.to change {
- memory_cache.size
+ cache.size
}.from(1).to(0)
end
it 'can iterate over keys under a prefix' do
- memory_cache['foo'] = 'bar'
- expect(memory_cache.to_a).to eq [ %w[ test-foo bar ] ]
+ cache['foo'] = 'bar'
+ expect(cache.to_a).to eq [ %w[ test-foo bar ] ]
end
end