class RSpec::Matchers::BuiltIn::DynamicPredicate
Not intended to be inherited directly.
Provides the implementation for dynamic predicate matchers.
@api private
def description
-
(String)
-
Other tags:
- Api: - private
def description "#{method_description}#{args_to_sentence}" end
def does_not_match?(actual, &block)
- Private: -
def does_not_match?(actual, &block) @actual = actual @block ||= block predicate_accessible? && predicate_matches?(false) end
def expectation_of(value)
def expectation_of(value) if RSpec::Expectations.configuration.strict_predicate_matchers? "return #{value}" elsif value "be truthy" else "be falsey" end end
def failure_message
-
(String)
-
Other tags:
- Api: - private
def failure_message failure_message_expecting(true) end
def failure_message_expecting(value)
def failure_message_expecting(value) validity_message || "expected `#{actual_formatted}.#{predicate}#{args_to_s}` to #{expectation_of value}, got #{description_of @predicate_result}" end
def failure_message_when_negated
-
(String)
-
Other tags:
- Api: - private
def failure_message_when_negated failure_message_expecting(false) end
def failure_to_respond_explanation
def failure_to_respond_explanation if private_predicate? " but `#{predicate}` is a private method" end end
def initialize(method_name, *args, &block)
def initialize(method_name, *args, &block) @method_name, @args, @block = method_name, args, block end
def matches?(actual, &block)
- Private: -
def matches?(actual, &block) @actual = actual @block ||= block predicate_accessible? && predicate_matches? end
def method_description
def method_description EnglishPhrasing.split_words(@method_name) end
def methods_include?(method)
def methods_include?(method) @actual.methods.include?(method.to_s) end
def methods_include?(method)
def methods_include?(method) @actual.methods.include?(method) end
def predicate_accessible?
def predicate_accessible? really_responds_to?(predicate) end
def predicate_matches?(value=true)
def predicate_matches?(value=true) if RSpec::Expectations.configuration.strict_predicate_matchers? value == predicate_result else value == !!predicate_result end end
def predicate_method_name
def predicate_method_name predicate end
def predicate_result
def predicate_result @predicate_result = actual.__send__(predicate_method_name, *@args, &@block) end
def private_predicate?
def private_predicate? @actual.private_methods.include? predicate.to_s end
def private_predicate?
def private_predicate? @actual.private_methods.include? predicate end
def really_responds_to?(method)
def really_responds_to?(method) if RSpec::Mocks::Double === @actual @actual.respond_to?(method) && methods_include?(method) else @actual.respond_to?(method) end end
def really_responds_to?(method)
def really_responds_to?(method) @actual.respond_to?(method) end
def root
def root # On 1.9, there appears to be a bug where String#match can return `false` # rather than the match data object. Changing to Regex#match appears to # work around this bug. For an example of this bug, see: # https://travis-ci.org/rspec/rspec-expectations/jobs/27549635 self.class::REGEX.match(@method_name.to_s).captures.first end
def validity_message
def validity_message return nil if predicate_accessible? "expected #{actual_formatted} to respond to `#{predicate}`#{failure_to_respond_explanation}" end