File: test_helper.rb

package info (click to toggle)
ruby-ansi 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 404 kB
  • sloc: ruby: 1,880; makefile: 5
file content (46 lines) | stat: -rw-r--r-- 704 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
require 'minitest/autorun'

class Tests < Minitest::Test
end

class Handler
  def initialize(obj)
    @obj = obj.name.gsub(/::/, "_")
  end

  def method(m, &block)
    @method = m
    instance_eval(&block)
  end

  alias :class_method :method

  def test(name = nil, &block)
    name = name.gsub(/\W/, "_") if name
    Tests.define_method("test_#{@obj}_#{@method}_#{name}", &block)
  end
end

class Object
  def assert
    Assertion.new(self)
  end
end

class Assertion
  def initialize(target)
    @target = target
  end

  def ==(other)
    unless @target == other
      raise RuntimeError
    end
  end

end

def testcase(obj, &block)
  handler = Handler.new(obj)
  handler.instance_eval(&block)
end