File: helper.rb

package info (click to toggle)
ruby-http-cookie 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 296 kB
  • sloc: ruby: 3,478; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,112 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'rubygems'
require 'test-unit'
require 'uri'
require 'http/cookie'

module Test
  module Unit
    module Assertions
      def assert_warn(pattern, message = nil, &block)
        class << (output = +"")
          alias write <<
        end
        stderr, $stderr = $stderr, output
        yield
        assert_match(pattern, output, message)
      ensure
        $stderr = stderr
      end

      def assert_warning(pattern, message = nil, &block)
        verbose, $VERBOSE = $VERBOSE, true
        assert_warn(pattern, message, &block)
      ensure
        $VERBOSE = verbose
      end
    end
  end
end

module Enumerable
  def combine
    masks = inject([[], 1]){|(ar, m), e| [ar << m, m << 1 ] }[0]
    all = masks.inject(0){ |al, m| al|m }

    result = []
    for i in 1..all do
      tmp = []
      each_with_index do |e, idx|
        tmp << e unless (masks[idx] & i) == 0
      end
      result << tmp
    end
    result
  end
end

def test_file(filename)
  File.expand_path(filename, File.dirname(__FILE__))
end

def sleep_until(time)
  if (s = time - Time.now) > 0
    sleep s + 0.01
  end
end