Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'spec_helper'
describe KV do
describe '#set' do
it 'assigns a value to the instance variable hash' do
kv = KV.new
kv.set('foo', 'bar')
expect(kv.hash['foo'][Time.now.to_i]).to eq('bar')
end
end
describe '#get' do
context 'timestamp is not supplied' do
it 'gets the value of the hash assigned' do
kv = KV.new
kv.set('foo', 'bar')
sleep(1)
kv.set('foo', 'bar2')
expect(kv.get('foo')).to eq('bar2')
end
end
context 'timestamp is suppied along with the key' do
it 'gets the value of the key with time closest to the timestamp' do
kv = KV.new
kv.set('foo', 'bar')
now = Time.now.to_i
sleep(1)
kv.set('foo', 'bar2')
expect(kv.get('foo', now)).to eq('bar')
end
end
context 'fuzzy matching' do
it 'does something' do
kv = KV.new
now = Time.now.to_i
kv.set('foo', 'bar')
sleep(3)
kv.set('foo', 'bar2')
# Fetch the key 'foo' with the 'now' timestamp, plus 2 seconds
expect(kv.get('foo', now + 2)).to eq('bar')
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.