Skip to content

Instantly share code, notes, and snippets.

@jimweirich jimweirich/run.out
Created Sep 3, 2013

Embed
What would you like to do?
$ rspec xx_spec.rb
....
Finished in 0.00287 seconds
4 examples, 0 failures
# require 'spec_helper'
# require 'branch_cache'
# require 'changeset_cache'
# Fake out stuff I don'e have
require 'rspec/given'
CacheMissException = Class.new(StandardError)
class Cache
def initialize
@hash = {}
end
def store(key, data)
@hash[key] = data
end
def fetch(key)
@hash[key] or fail(CacheMissException)
end
end
class BranchCache < Cache
end
class ChangesetCache < Cache
end
# Shared Examples
shared_examples "cached data" do
Given(:cache) { described_class.new }
context "can store and retreive changeset data by branch as a set" do
Given(:data) { %w(data fake some) }
When { cache.store("Big Branch", data) }
Then { cache.fetch("Big Branch").sort.should eq(data) }
end
context "returns CacheMissException if lookup value with no data" do
When(:result) { cache.fetch("Fake Branch") }
Then { result.should have_failed(CacheMissException) }
end
end
describe BranchCache do
it_behaves_like "cached data"
end
describe ChangesetCache do
it_behaves_like "cached data"
end
@plukevdh

This comment has been minimized.

Copy link

commented Sep 3, 2013

Ah, you're right. I had the block level of the describes wrong. Thanks for the quick check!

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.