Skip to content

Instantly share code, notes, and snippets.

@saadbinakhlaq
Created September 22, 2016 18:17
Show Gist options
  • Save saadbinakhlaq/6bfc3904760c3ffcea4ca793f22469a6 to your computer and use it in GitHub Desktop.
Save saadbinakhlaq/6bfc3904760c3ffcea4ca793f22469a6 to your computer and use it in GitHub Desktop.
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