Module: Test::Unit::Assertions

Defined in:
lib/core_assertions.rb

Instance Method Summary collapse

Instance Method Details

#_assertionsObject

:nodoc:



51
52
53
# File 'lib/core_assertions.rb', line 51

def _assertions # :nodoc:
  @_assertions ||= 0
end

#_assertions=(n) ⇒ Object

:nodoc:



47
48
49
# File 'lib/core_assertions.rb', line 47

def _assertions= n # :nodoc:
  @_assertions = n
end

#assert_raises(*exp, &b) ⇒ Object

Raises:

  • (NoMethodError)


43
44
45
# File 'lib/core_assertions.rb', line 43

def assert_raises(*exp, &b)
  raise NoMethodError, "use assert_raise", caller
end

#message(msg = nil, ending = nil, &default) ⇒ Object

Returns a proc that will output msg along with the default message.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/core_assertions.rb', line 58

def message msg = nil, ending = nil, &default
  proc {
    ending ||= (ending_pattern = /(?<!\.)\z/; ".")
    ending_pattern ||= /(?<!#{Regexp.quote(ending)})\z/
    msg = msg.call if Proc === msg
    ary = [msg, (default.call if default)].compact.reject(&:empty?)
    ary.map! {|str| str.to_s.sub(ending_pattern, ending) }
    begin
      ary.join("\n")
    rescue Encoding::CompatibilityError
      ary.map(&:b).join("\n")
    end
  }
end