module RSpec::SleepingKingStudios::Matchers::Shared::MatchProperty
Helper methods for checking reader and writer methods and values.
Private Instance Methods
Checks whether the value of the predicate matches the expected value. If the value looks like an RSpec
matcher (it responds to :matches?), runs value.matches?(); otherwise checks for equality using :==.
@return [Boolean] true if the value matches the expected value; otherwise
false.
# File lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb, line 14 def matches_predicate_value? return false unless responds_to_predicate? return true unless @value_set actual_value = @actual.send(:"#{@expected}?") @matches_predicate_value = (@value.respond_to?(:matches?) && @value.respond_to?(:description)) ? @value.matches?(actual_value) : @value == actual_value end
Checks whether the value of the reader matches the expected value. If the value looks like an RSpec
matcher (it responds to :matches?), runs value.matches?(); otherwise checks for equality using :==.
@return [Boolean] true if the value matches the expected value; otherwise
false.
# File lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb, line 31 def matches_reader_value? allow_private: false return false unless responds_to_reader?(:allow_private => allow_private) return true unless @value_set actual_value = @actual.send(@expected) @matches_reader_value = (@value.respond_to?(:matches?) && @value.respond_to?(:description)) ? @value.matches?(actual_value) : @value == actual_value end
Checks whether the object responds to the predicate method :#{property}?.
@return [Boolean] true if the object responds to the method; otherwise
false.
# File lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb, line 46 def responds_to_predicate? @matches_predicate = @actual.respond_to?(:"#{@expected}?") end
Checks whether the object responds to the reader method :#{property}.
@return [Boolean] true if the object responds to the method; otherwise
false.
# File lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb, line 54 def responds_to_reader? allow_private: false @matches_reader = @actual.respond_to?(@expected, allow_private) end
Checks whether the object responds to the writer method :#{property}=.
@return [Boolean] true if the object responds to the method; otherwise
false.
# File lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb, line 62 def responds_to_writer? allow_private: false @matches_writer = @actual.respond_to?(:"#{@expected}=", allow_private) end
Formats the expected value as a human-readable string. If the value looks like an RSpec
matcher (it responds to :matches? and :description), calls value#description; otherwise calls value#inspect.
@return [String] the value as a human-readable string.
# File lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb, line 71 def value_to_string return @value.description if @value.respond_to?(:matches?) && @value.respond_to?(:description) @value.inspect end