module Declare::Assertions
Public Instance Methods
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
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
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?
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
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
MATCH?(condition)
click to toggle source
@param [#===] condition
# File lib/declare/assertions.rb, line 109 def MATCH?(condition) condition === @it end
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?
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
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?
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
TRUTHY?(object)
click to toggle source
# File lib/declare/assertions.rb, line 177 def TRUTHY?(object) !!object end
Also aliased as: 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