Skip to content

Commit 47be090

Browse files
dougbarthNZKoz
authored andcommitted
Skip tests that depend on memcached if not running.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
1 parent 4b63c27 commit 47be090

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

activesupport/test/abstract_unit.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def uses_mocha(test_name, &block)
2626
end
2727
end
2828

29+
unless defined? uses_memcached
30+
def uses_memcached(test_name)
31+
require 'memcache'
32+
MemCache.new('localhost').stats
33+
yield
34+
rescue MemCache::MemCacheError
35+
$stderr.puts "Skipping #{test_name} tests. Start memcached and try again."
36+
end
37+
end
38+
2939
# Show backtraces for deprecated behavior for quicker cleanup.
3040
ActiveSupport::Deprecation.debug = true
3141

@@ -40,4 +50,4 @@ def with_kcode(code)
4050
else
4151
yield
4252
end
43-
end
53+
end

activesupport/test/caching_test.rb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,28 @@ def test_store_objects_should_be_immutable
146146
end
147147
end
148148

149-
class MemCacheStoreTest < Test::Unit::TestCase
150-
def setup
151-
@cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
152-
@cache.clear
153-
end
149+
uses_memcached 'memcached backed store' do
150+
class MemCacheStoreTest < Test::Unit::TestCase
151+
def setup
152+
@cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
153+
@cache.clear
154+
end
154155

155-
include CacheStoreBehavior
156+
include CacheStoreBehavior
156157

157-
def test_store_objects_should_be_immutable
158-
@cache.write('foo', 'bar')
159-
@cache.read('foo').gsub!(/.*/, 'baz')
160-
assert_equal 'bar', @cache.read('foo')
158+
def test_store_objects_should_be_immutable
159+
@cache.write('foo', 'bar')
160+
@cache.read('foo').gsub!(/.*/, 'baz')
161+
assert_equal 'bar', @cache.read('foo')
162+
end
161163
end
162-
end
163164

164-
class CompressedMemCacheStore < Test::Unit::TestCase
165-
def setup
166-
@cache = ActiveSupport::Cache.lookup_store(:compressed_mem_cache_store)
167-
@cache.clear
168-
end
165+
class CompressedMemCacheStore < Test::Unit::TestCase
166+
def setup
167+
@cache = ActiveSupport::Cache.lookup_store(:compressed_mem_cache_store)
168+
@cache.clear
169+
end
169170

170-
include CacheStoreBehavior
171+
include CacheStoreBehavior
172+
end
171173
end

0 commit comments

Comments
 (0)