Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Timecop to simulate time in tests. Make tests independent #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source :rubygems

gemspec

group :development, :test do
gem 'rake'
end
Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
PATH
remote: .
specs:
diskcached (1.1.0)

GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.3)
json (1.8.1)
memcached (1.4.3)
multi_json (1.3.6)
rake (0.9.2.2)
rdoc (4.1.1)
json (~> 1.4)
redcarpet (2.1.1)
rspec (2.11.0)
rspec-core (~> 2.11.0)
Expand All @@ -18,15 +26,19 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
timecop (0.7.1)
yard (0.8.2.1)

PLATFORMS
ruby

DEPENDENCIES
diskcached!
memcached
rake
rdoc
redcarpet
rspec
simplecov
timecop
yard
1 change: 1 addition & 0 deletions diskcached.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec"
s.add_development_dependency "simplecov"
s.add_development_dependency "rdoc"
s.add_development_dependency "timecop"

s.files = Dir.glob("lib/**/*") + %w(README.md HISTORY.md Benchmark.md Gemfile Rakefile)
s.require_path = 'lib'
Expand Down
24 changes: 10 additions & 14 deletions lib/diskcached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,18 @@ def set key, value
# which exist and aren't expired, it raises
# Diskcache::NotFound if none are available
def get key
begin
if key.is_a? Array
hash = {}
key.each do |k|
hash[k] = Marshal::load(read_cache_file(k)) unless expired?(k)
end
flush_expired if gc_auto
return hash unless hash.empty?
else
flush_expired if gc_auto
return Marshal::load(read_cache_file(key)) unless expired?(key)
if key.is_a? Array
hash = {}
key.each do |k|
hash[k] = Marshal::load(read_cache_file(k)) unless expired?(k)
end
raise Diskcached::NotFound
rescue
raise Diskcached::NotFound
flush_expired if gc_auto
return hash unless hash.empty?
else
flush_expired if gc_auto
return Marshal::load(read_cache_file(key)) unless expired?(key)
end
raise Diskcached::NotFound
end

# returns path to cache file with 'key'
Expand Down
Loading