Sha256: ea36730e6b64378333517476b81cbc1695c78a12e49142ff1aad8f5a2ec52bb7

Contents?: true

Size: 1.33 KB

Versions: 13

Compression:

Stored size: 1.33 KB

Contents

require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'mocha'
require 'pp'

$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
require 'memcache'

class Test::Unit::TestCase
  @@servers ||= {}
  def init_memcache(*ports)
    ports.each do |port|
      @@servers[port] ||= start_memcache(port)
    end

    @memcache = yield
    @memcache.flush_all
  end

  def m
    @memcache
  end

  def start_memcache(port)
    system("memcached -p #{port} -U 0 -d -P /tmp/memcached_#{port}.pid")
    sleep 1
    File.read("/tmp/memcached_#{port}.pid")
  end

  def self.with_prefixes(*prefixes)
    # Define new test_* methods that calls super for every prefix. This only works for
    # methods that are mixed in, and should be called before you define custom test methods.
    opts = prefixes.last.is_a?(Hash) ? prefixes.last : {}
    instance_methods.each do |method_name|
      next unless method_name =~ /^test_/
      next if opts[:except] and opts[:except].include?(method_name)
      next if opts[:only] and not opts[:only].include?(method_name)

      define_method(method_name) do |*args|
        prefixes.each do |prefix|
          assert_equal prefix, m.prefix = prefix
          assert_equal prefix, m.prefix
          super
          assert_equal nil, m.prefix = nil
          assert_equal nil, m.prefix
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
memcache-1.2.13 test/test_helper.rb
memcache-1.2.12 test/test_helper.rb
memcache-1.2.11 test/test_helper.rb
memcache-1.2.10 test/test_helper.rb
memcache-1.2.9 test/test_helper.rb
memcache-1.2.8 test/test_helper.rb
memcache-1.2.7 test/test_helper.rb
memcache-1.2.6 test/test_helper.rb
memcache-1.2.5 test/test_helper.rb
memcache-1.2.4 test/test_helper.rb
memcache-1.2.3 test/test_helper.rb
memcache-1.2.2 test/test_helper.rb
memcache-1.2.1 test/test_helper.rb