Skip tests that depend on memcached if not running.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
Doug Barth
2008-10-14 15:30:46 -05:00
committed by Michael Koziarski
parent 4b63c2700f
commit 47be090d37
2 changed files with 31 additions and 19 deletions

View File

@@ -26,6 +26,16 @@ unless defined? uses_mocha
end
end
unless defined? uses_memcached
def uses_memcached(test_name)
require 'memcache'
MemCache.new('localhost').stats
yield
rescue MemCache::MemCacheError
$stderr.puts "Skipping #{test_name} tests. Start memcached and try again."
end
end
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
@@ -40,4 +50,4 @@ def with_kcode(code)
else
yield
end
end
end

View File

@@ -146,26 +146,28 @@ class MemoryStoreTest < Test::Unit::TestCase
end
end
class MemCacheStoreTest < Test::Unit::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
@cache.clear
uses_memcached 'memcached backed store' do
class MemCacheStoreTest < Test::Unit::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
@cache.clear
end
include CacheStoreBehavior
def test_store_objects_should_be_immutable
@cache.write('foo', 'bar')
@cache.read('foo').gsub!(/.*/, 'baz')
assert_equal 'bar', @cache.read('foo')
end
end
include CacheStoreBehavior
class CompressedMemCacheStore < Test::Unit::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:compressed_mem_cache_store)
@cache.clear
end
def test_store_objects_should_be_immutable
@cache.write('foo', 'bar')
@cache.read('foo').gsub!(/.*/, 'baz')
assert_equal 'bar', @cache.read('foo')
include CacheStoreBehavior
end
end
class CompressedMemCacheStore < Test::Unit::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:compressed_mem_cache_store)
@cache.clear
end
include CacheStoreBehavior
end