Sha256: cd0608cb57769d77cbcf061c7313e636e48c66745bb31e4834ce179814340c32

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

require 'ae/assertor'

module AE

  # = Assert
  #
  module Assert

    # Assert a operational relationship.
    #
    #   4.assert == 3
    #
    # If only a single test argument is given then
    # #assert simple validates that it evalutate to true.
    # An optional message argument can be given in this
    # case which will be used instead of the deafult message.
    #
    #   assert(4==3, "not the same thing")
    #
    # In block form, #assert ensures the block evalutes
    # truthfully, i.e. not as nil or false.
    #
    #   assert{ 4==3 }
    #
    def assert(*args, &block)
      Assertor.new(self, :backtrace=>caller).assert(*args, &block)
    end

    # Same as 'object.assert == other'.
    def assert=(cmp)
      Assertor.new(self, :backtrace=>caller).assert == cmp
    end

    # Assert not an operational relationship.
    # Read it as "assert not".
    #
    #   4.refute == 4  #=> Assertion Error
    #
    # See #assert.
    def refute(*args, &block)
      Assertor.new(self, :backtrace=>caller).not.assert(*args, &block)
    end

    # Same as 'object.assert == other'.
    def refute=(cmp)
      Assertor.new(self, :backtrace=>caller).not.assert == cmp
    end

    # Alias for #assert!.
    #
    #   4.assert! == 4
    #
    # NOTE: This method would not be necessary if Ruby would allow
    # +!=+ to be define as a method, or at least +!+ as a unary method.
    # This may be possible in Ruby 1.9.
    alias_method :assert!, :refute
   
  end

end

class ::Object #:nodoc:
  include AE::Assert
end

# Copyright (c) 2008,2009 Thomas Sawyer

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ae-1.6.1 lib/ae/assert.rb
ae-1.6.0 lib/ae/assert.rb
ae-1.5.0 lib/ae/assert.rb
ae-1.4.0 lib/ae/assert.rb