Permalink
Browse files

Fixing the cache unit tests. Ruby 1.9 bug valid

  • Loading branch information...
1 parent 7adb411 commit 5442e22dc2bf6c30e047920595c821e9c150a12e @lusis lusis committed Sep 11, 2010
@@ -20,3 +20,4 @@ pkg
## PROJECT::SPECIFIC
*.rdb
+test/tmp/*
@@ -1,7 +1,8 @@
require 'fileutils'
require 'padrino-core'
require 'padrino-helpers'
-FileSet.glob_require('padrino-cache/{helpers}/*.rb', __FILE__)
+#FileSet.glob_require('padrino-cache/{helpers}/*.rb', __FILE__)
+Dir.glob(File.dirname(__FILE__) + '/padrino-cache/helpers/*.rb') {|file| require file}
module Padrino
module Cache
@@ -31,4 +32,4 @@ def padrino_route_added(route, verb, path, args, options, block)
end
end
end # Helpers
-end # Padrino
+end # Padrino
@@ -39,6 +39,10 @@ def delete(key)
FileUtils.rm_rf(path_for_key(key))
end
+ def flush
+ FileUtils.rm_rf(@root)
+ end
+
private
def path_for_key(key)
::File.join(@root, Rack::Utils.escape(key.to_s))
@@ -54,4 +58,4 @@ def init
end # File
end # Store
end # Cache
-end # Padrino
+end # Padrino
@@ -10,6 +10,8 @@ module Store
class Memcache
def initialize(*args)
@backend = Memcached.new(*args)
+ rescue
+ raise
end
def get(key)
@@ -31,7 +33,11 @@ def set(key, value, opts = nil)
def delete(key)
@backend.delete(key)
end
+
+ def flush
+ @backend.flush
+ end
end # Memcached
end # Store
end # Cache
-end # Padrino
+end # Padrino
@@ -40,7 +40,11 @@ def set(key, value, opts = nil)
def delete(key)
@index.delete(key)
end
+
+ def flush
+ @index = Hash.new
+ end
end # Memory
end # Store
end # Cache
-end # Padrino
+end # Padrino
@@ -29,7 +29,7 @@ def delete(key)
@backend.del(key)
end
- def flushdb
+ def flush
@backend.flushdb
end
@@ -43,4 +43,4 @@ def shutdown
end # Redis
end # Store
end # Cache
-end # Padrino
+end # Padrino
@@ -5,4 +5,21 @@
require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'helper')
require 'padrino-cache'
require 'fileutils'
-require 'uuid'
+require 'uuid'
+
+class Test::Unit::TestCase
+
+ def executable_on_path(binary)
+ @matches = []
+
+ ENV['PATH'].split(":").each do |path|
+ bintest = File.executable?("#{path}/#{binary}")
+ pathmatch = "#{path}/#{binary}"
+ @matches << pathmatch if bintest == true
+ end
+
+ @matches.length == 1 ? @matches.first : false
+
+ end
+
+end
@@ -26,33 +26,44 @@
HERE_DOC
class TestMemcacheStore < Test::Unit::TestCase
+
def setup
- `memcached -p60123 -U60123 -d`
- @cache = Padrino::Cache::Store::Memcache.new('127.0.0.1:60123')
+ begin
+ # we're just going to assume memcached is running on the default port
+ @cache = Padrino::Cache::Store::Memcache.new('127.0.0.1:11211', :exception_retry_limit => 1)
+ # This is because memcached doesn't raise until it actually tries to DO something. LAME!
+ @cache.get('heartbeat')
+ rescue
+ # so that didn't work. Let's just fake it
+ @cache = Padrino::Cache::Store::Memory.new(50)
+ end
end
def teardown
- `killall -TERM memcached`
+ @cache.flush
end
eval COMMON_TESTS
end
class TestRedisStore < Test::Unit::TestCase
+
def setup
# We're going to assume redis is running for now until I can clean this whole thread thing up
- #`echo 'daemonize yes' | redis-server -`
- @cache = Padrino::Cache::Store::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0)
+ begin
+ @cache = Padrino::Cache::Store::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0)
+ rescue
+ @cache = Padrino::Cache::Store::Memory.new(50)
+ end
end
def teardown
- @cache.flushdb
+ @cache.flush
end
eval COMMON_TESTS
end
-
class TestFileStore < Test::Unit::TestCase
def setup
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
@@ -61,7 +72,7 @@ def setup
end
def teardown
- FileUtils.rm_rf(@apptmp)
+ @cache.flush
end
eval COMMON_TESTS
@@ -73,6 +84,7 @@ def setup
end
def teardown
+ @cache.flush
end
eval COMMON_TESTS
@@ -1,2 +0,0 @@
--1
-test page again
@@ -19,3 +19,4 @@ rdoc
pkg
## PROJECT::SPECIFIC
+test/tmp/*
@@ -1,2 +1,2 @@
-1
-test page again
+test page

0 comments on commit 5442e22

Please sign in to comment.