Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Created September 3, 2013 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimweirich/6425566 to your computer and use it in GitHub Desktop.
Save jimweirich/6425566 to your computer and use it in GitHub Desktop.
$ 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
Copy link

plukevdh 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