class RSpec::SleepingKingStudios::Matchers::BuiltIn::BeAKindOfMatcher
Extensions to the built-in RSpec
be_kind_of matcher.
Public Instance Methods
description()
click to toggle source
(see BaseMatcher#description
)
# File lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb, line 10 def description message = "be #{type_string}" end
failure_message()
click to toggle source
(see BaseMatcher#failure_message
)
# File lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb, line 29 def failure_message "expected #{@actual.inspect} to be #{type_string}" end
failure_message_when_negated()
click to toggle source
(see BaseMatcher#failure_message_when_negated
)
# File lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb, line 34 def failure_message_when_negated "expected #{@actual.inspect} not to be #{type_string}" end
match(expected, actual)
click to toggle source
Checks if the object matches one of the specified types. Allows an expected value of nil as a shortcut for expecting an instance of NilClass.
@param [Module, nil, Array<Module, nil>] expected The type or types to
check the object against.
@param [Object] actual The object to check.
@return [Boolean] True if the object matches one of the specified types,
otherwise false.
# File lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb, line 24 def match expected, actual match_type? expected end
Private Instance Methods
match_type?(expected)
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb, line 40 def match_type? expected case when expected.nil? @actual.nil? when expected.is_a?(Enumerable) expected.reduce(false) { |memo, obj| memo || match_type?(obj) } else @actual.kind_of? expected end # case end
type_string()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb, line 51 def type_string case when @expected.nil? @expected.inspect when @expected.is_a?(Enumerable) && 1 < @expected.count tools = ::SleepingKingStudios::Tools::ArrayTools items = @expected.map { |value| value.nil? ? 'nil' : value } "a #{tools.humanize_list items, :last_separator => ' or '}" else "a #{expected}" end # case end