module Declare::Assertions

Public Instance Methods

A(klass)
Also aliased as: a
Alias for: INSTANCE_OF
A?(klass)
Also aliased as: a?
Alias for: INSTANCE_OF?
CAN(message)
Also aliased as: can
Alias for: RESPOND
CATCH(exception_klass) { || ... } click to toggle source

pass if occurred the error is just a own instance @param [Class] exception_klass

# File lib/declare/assertions.rb, line 238
def CATCH(exception_klass, &block)
  yield
rescue ::Exception
  if $!.instance_of?(exception_klass)
    pass
  else
    failure("Faced a exception, that instance of #{exception_klass}.",
            "Faced a exception, that instance of #{$!.class}.", 2)
  end
else
  failure("Faced a exception, that instance of #{exception_klass}.",
          'The block was not faced any exceptions.', 2)
ensure
  _declared!
end
EQL(sample) click to toggle source
# File lib/declare/assertions.rb, line 59
def EQL(sample)
  if EQL?(sample)
    pass
  else
    failure('It\'s able to use key in any Hash object.')
  end
ensure
  _declared!
end
Also aliased as: eql
EQL?(sample) click to toggle source

true if can use for hash-key

# File lib/declare/assertions.rb, line 54
def EQL?(sample)
  @it.eql?(sample) && sample.eql?(@it) && (@it.hash == sample.hash) &&
    { @it => true }.key?(sample)
end
EQUAL(other) click to toggle source
# File lib/declare/assertions.rb, line 138
def EQUAL(other)
  if EQUAL?(other)
    pass
  else
    failure('@it.equal?(other) && other.equal?(@it) && (@it.__id__.equal? other.__id__) #=> truthy',
            "falsy, it(#{@it.__id__}), other(#{other.__id__})")
  end
ensure
  _declared!
end
Also aliased as: equal, SAME
EQUAL?(other) click to toggle source

true if bidirectional passed equal, and __id__ is same value

# File lib/declare/assertions.rb, line 134
def EQUAL?(other)
  @it.equal?(other) && other.equal?(@it) && @it.__id__.equal?(other.__id__)
end
FALSY(object) click to toggle source
# File lib/declare/assertions.rb, line 204
def FALSY(object)
  if FALSY?(object)
    pass
  else
    failure('It is a falsy(nil/false) object.',
            "\"#{object.inspect}\" is a truthy(not nil/false) object.")
  end
ensure
  _declared!
end
Also aliased as: falsy, NG
FALSY?(object) click to toggle source
# File lib/declare/assertions.rb, line 198
def FALSY?(object)
  !object
end
Also aliased as: falsy?
INSTANCE_OF(klass) click to toggle source

@param [Class] klass

# File lib/declare/assertions.rb, line 15
def INSTANCE_OF(klass)
  if INSTANCE_OF?(klass)
    pass
  else
    failure("It is #{klass}'s instance.",
            "It is #{@it.class}'s instance.")
  end
ensure
  _declared!
end
Also aliased as: A
INSTANCE_OF?(klass) click to toggle source

@param [Class] klass

# File lib/declare/assertions.rb, line 7
def INSTANCE_OF?(klass)
  @it.instance_of?(klass)
end
Also aliased as: A?
IS(other) click to toggle source
# File lib/declare/assertions.rb, line 78
def IS(other)
  if IS?(other)
    pass
  else
    failure('it == other',
            "#{@it.inspect} == #{other.inspect}")
  end
ensure
  _declared!
end
Also aliased as: is
IS?(other, bidirectional: true) click to toggle source

true if under “==”

# File lib/declare/assertions.rb, line 72
def IS?(other, bidirectional: true)
  (@it == other) && (bidirectional ? (other == @it) : true)
end
Also aliased as: is?
IS_A(family)
Also aliased as: is_a
Alias for: KIND_OF
KIND(family)
Also aliased as: kind
Alias for: KIND_OF
KIND?(family)
Also aliased as: kind?
Alias for: KIND_OF?
KIND_OF(family) click to toggle source
# File lib/declare/assertions.rb, line 36
def KIND_OF(family)
  if KIND_OF?(family)
    pass
  else
    failure("It is kind of #{family.inspect}.",
            (family.kind_of?(Module) ? "It.class(#{@it.class}) <-> other.ancestors(#{family.ancestors})" : "It is not kind of #{family.inspect}"))
  end
ensure
  _declared!
end
Also aliased as: kind_of, KIND, IS_A
KIND_OF?(family) click to toggle source
# File lib/declare/assertions.rb, line 29
def KIND_OF?(family)
  @it.kind_of?(family)
end
Also aliased as: KIND?
MATCH(condition) click to toggle source

@param [#===] condition

# File lib/declare/assertions.rb, line 118
def MATCH(condition)
  if ret = MATCH?(condition)
    pass
  else
    failure("return(#{condition} === It) is not nil/false.",
            "return(#{ret}).")
  end
ensure
  _declared!
end
Also aliased as: match, SATISFY
MATCH?(condition) click to toggle source

@param [#===] condition

# File lib/declare/assertions.rb, line 109
def MATCH?(condition)
  condition === @it
end
Also aliased as: match?, SATISFY?
NG(object)
Also aliased as: ng
Alias for: FALSY
NOT(other) click to toggle source
# File lib/declare/assertions.rb, line 97
def NOT(other)
  if NOT?(other)
    pass
  else
    failure("It is not other(#{other.inspect}).",
            "It is other(#{other.inspect}).")
  end
ensure
  _declared!
end
NOT?(other) click to toggle source
# File lib/declare/assertions.rb, line 91
def NOT?(other)
  (@it != other) && (other != @it) && !IS?(other)
end
Also aliased as: not?
OK(object)
Also aliased as: ok
Alias for: TRUTHY
RESCUE(exception_klass) { || ... } click to toggle source

pass if occurred the error is a own/subclasses instance @param [Class] exception_klass

# File lib/declare/assertions.rb, line 221
def RESCUE(exception_klass, &block)
  fmt_err = ->err_cls { err_cls.ancestors.take_while { |mod| mod != Object }.join(' < ') }
  yield
rescue exception_klass
  pass
rescue ::Exception
  failure("Faced a exception, that kind of #{exception_klass}(#{fmt_err.call(exception_klass)}).",
          "Faced a exception, that instance of #{$!.class}(#{fmt_err.call($!.class)}).", 2)
else
  failure("Faced a exception, that kind of #{exception_klass}(#{fmt_err.call(exception_klass)}).",
          'The block was not faced any exceptions.', 2)
ensure
  _declared!
end
RESPOND(message) click to toggle source
# File lib/declare/assertions.rb, line 160
def RESPOND(message)
  message = message.to_sym

  if ret = RESPOND?(message)
    pass
  else
    failure("It.respond_to?(#{message.inspect}) #=> truthy(not nil/false)",
            "It.respond_to?(#{message.inspect}) #=> #{ret.inspect}")
  end
ensure
  _declared!
end
Also aliased as: respond, CAN
RESPOND?(message) click to toggle source

true if under “respond_to?”

# File lib/declare/assertions.rb, line 154
def RESPOND?(message)
  @it.respond_to?(message)
end
Also aliased as: respond?
SAME(other)
Also aliased as: same
Alias for: EQUAL
SATISFY(condition)
Also aliased as: satisfy
Alias for: MATCH
SATISFY?(condition)
Also aliased as: satisfy?
Alias for: MATCH?
TRUTHY(object) click to toggle source
# File lib/declare/assertions.rb, line 183
def TRUTHY(object)
  if TRUTHY?(object)
    pass
  else
    failure('It is a truthy(not nil/false) object.',
            "\"#{object.inspect}\" is a falsy(nil/false) object.")
  end
ensure
  _declared!
end
Also aliased as: truthy, OK
TRUTHY?(object) click to toggle source
# File lib/declare/assertions.rb, line 177
def TRUTHY?(object)
  !!object
end
Also aliased as: truthy?
a(klass)
Alias for: A
a?(klass)
Alias for: A?
can(message)
Alias for: CAN
eql(sample)
Alias for: EQL
equal(other)
Alias for: EQUAL
falsy(object)
Alias for: FALSY
falsy?(object)
Alias for: FALSY?
is(other)
Alias for: IS
is?(other, bidirectional: true)
Alias for: IS?
is_a(family)
Alias for: IS_A
kind(family)
Alias for: KIND
kind?(family)
Alias for: KIND?
kind_of(family)
Alias for: KIND_OF
match(condition)
Alias for: MATCH
match?(condition)
Alias for: MATCH?
ng(object)
Alias for: NG
not?(other)
Alias for: NOT?
ok(object)
Alias for: OK
respond(message)
Alias for: RESPOND
respond?(message)
Alias for: RESPOND?
same(other)
Alias for: SAME
satisfy(condition)
Alias for: SATISFY
satisfy?(condition)
Alias for: SATISFY?
truthy(object)
Alias for: TRUTHY
truthy?(object)
Alias for: TRUTHY?

Private Instance Methods

_declared!() click to toggle source
# File lib/declare/assertions.rb, line 256
def _declared!
  ::Declare.declared!
end
failure(expected, actual, level=1) click to toggle source
# File lib/declare/assertions.rb, line 264
def failure(expected, actual, level=1)
  ::Declare.failure!("#{_declare_called_from(level)}\n  Expected: #{expected}\n  Actual  : #{actual}\n\n")
end
pass() click to toggle source
# File lib/declare/assertions.rb, line 260
def pass
  ::Declare.pass!
end