Module: Assert

Overview

Copyright (C) 2004-2005 Tero Vuorela   

This program is free   This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA.

++

Defined Under Namespace

Classes: AssertionFailedException

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assert(condition, msg = nil) ⇒ Object



22
23
24
25
26
# File 'lib/common/assert.rb', line 22

def Assert.assert( condition, msg=nil )
  if ( condition != true )
    raise_exception( caller, 'condition was false', msg )
  end
end

.assert_nil(object, msg = nil) ⇒ Object



47
48
49
50
51
# File 'lib/common/assert.rb', line 47

def Assert.assert_nil( object, msg=nil )
  if ( object != nil )
    raise_exception( caller, "object #{object.class.to_s} was not nil", msg )
  end
end

.assert_not_nil(object, msg = nil) ⇒ Object



34
35
36
37
38
# File 'lib/common/assert.rb', line 34

def Assert.assert_not_nil( object, msg=nil )
  if ( object == nil )
    raise_exception( caller, 'object was nil', msg )
  end
end

.raise_exception(caller, checkMessage, message = nil) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/common/assert.rb', line 59

def Assert.raise_exception( caller, checkMessage, message=nil )
    msg = checkMessage
    if ( message != nil )
      msg << ': ' + message
    end
  raise AssertionFailedException, msg, caller
end

Instance Method Details

#assert(condition, msg = nil) ⇒ Object



29
30
31
# File 'lib/common/assert.rb', line 29

def assert( condition, msg=nil )
  Assert.assert( condition, msg )
end

#assert_nil(object, msg = nil) ⇒ Object



54
55
56
# File 'lib/common/assert.rb', line 54

def assert_nil( object, msg=nil )
  Assert.assert_nil( object, msg )
end

#assert_not_nil(object, msg = nil) ⇒ Object



41
42
43
# File 'lib/common/assert.rb', line 41

def assert_not_nil( object, msg=nil )
  Assert.assert_not_nil( object, msg )
end