~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/runit/assert.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Author:: Nathaniel Talbott.
2
 
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
 
# License:: Ruby license.
4
 
 
5
 
require 'test/unit/assertions'
6
 
require 'runit/error'
7
 
 
8
 
module RUNIT
9
 
  module AssertMixin
10
 
 
11
 
    def setup_assert
12
 
    end
13
 
 
14
 
    def assert_no_exception(*args, &block)
15
 
      assert_nothing_raised(*args, &block)
16
 
    end
17
 
 
18
 
    # To deal with the fact that RubyUnit does not check that the
19
 
    # regular expression is, indeed, a regular expression, if it is
20
 
    # not, we do our own assertion using the same semantics as
21
 
    # RubyUnit
22
 
    def assert_match(actual_string, expected_re, message="")
23
 
      _wrap_assertion {
24
 
        full_message = build_message(message, "Expected <?> to match <?>", actual_string, expected_re)
25
 
        assert_block(full_message) {
26
 
          expected_re =~ actual_string
27
 
        }
28
 
        Regexp.last_match
29
 
      }
30
 
    end
31
 
 
32
 
    def assert_not_nil(actual, message="")
33
 
      assert(!actual.nil?, message)
34
 
    end
35
 
 
36
 
    def assert_not_match(actual_string, expected_re, message="")
37
 
      assert_no_match(expected_re, actual_string, message)
38
 
    end
39
 
 
40
 
    def assert_matches(*args)
41
 
      assert_match(*args)
42
 
    end
43
 
 
44
 
    def assert_fail(message="")
45
 
      flunk(message)
46
 
    end
47
 
 
48
 
    def assert_equal_float(expected, actual, delta, message="")
49
 
      assert_in_delta(expected, actual, delta, message)
50
 
    end
51
 
 
52
 
    def assert_send(object, method, *args)
53
 
      super([object, method, *args])
54
 
    end
55
 
 
56
 
    def assert_exception(exception, message="", &block)
57
 
      assert_raises(exception, message, &block)
58
 
    end
59
 
 
60
 
    def assert_respond_to(method, object, message="")
61
 
      if (called_internally?)
62
 
        super
63
 
      else
64
 
        super(object, method, message)
65
 
      end
66
 
    end
67
 
 
68
 
    def called_internally?
69
 
      /assertions\.rb/.match(caller[1])
70
 
    end
71
 
  end
72
 
  module Assert
73
 
    include Test::Unit::Assertions
74
 
    include AssertMixin
75
 
  end
76
 
end