Class: RSpec::Matchers::BuiltIn::DynamicPredicate Private
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
RSpec::Matchers::BuiltIn::BePredicate, RSpec::Matchers::BuiltIn::Has
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
BaseMatcher
|
|
Instance Chain:
|
|
Inherits: |
RSpec::Matchers::BuiltIn::BaseMatcher
|
Defined in: | rspec-expectations/lib/rspec/matchers/built_in/has.rb |
Overview
Provides the implementation for dynamic predicate matchers. Not intended to be inherited directly.
Constant Summary
BaseMatcher
- Inherited
Class Method Summary
- .new(method_name, *args, &block) ⇒ DynamicPredicate constructor Internal use only
BaseMatcher
- Inherited
.matcher_name, .new, | |
.underscore | Borrowed from ActiveSupport. |
Instance Attribute Summary
- #predicate_accessible? ⇒ Boolean readonly private Internal use only
-
#private_predicate? ⇒ Boolean
readonly
private
Internal use only
:nocov:
BaseMatcher
- Inherited
#actual, | |
#diffable? |
|
#expected, #expects_call_stack_jump?, #matcher_name, #matcher_name=, #rescued_exception, | |
#supports_block_expectations? | Most matchers are value matchers (i.e. meant to work with ‘expect(value)`) rather than block matchers (i.e. meant to work with `expect { }`), so this defaults to false. |
#supports_value_expectations? |
BaseMatcher::StringEncodingFormatting
- Included
#string_encoding_differs? | :nocov: |
Instance Method Summary
- #description ⇒ String Internal use only
- #does_not_match?(actual, &block) ⇒ Boolean Internal use only
- #failure_message ⇒ String Internal use only
- #failure_message_when_negated ⇒ String Internal use only
- #matches?(actual, &block) ⇒ Boolean Internal use only
- #expectation_of(value) private Internal use only
- #failure_message_expecting(value) private Internal use only
- #failure_to_respond_explanation private Internal use only
- #method_description private Internal use only
-
#methods_include?(method)
private
See additional method definition at line 79.
- #predicate_matches?(value = true) ⇒ Boolean private Internal use only
- #predicate_method_name private Internal use only
- #predicate_result private Internal use only
-
#really_responds_to?(method) ⇒ Boolean
private
Internal use only
:nocov:
- #root private Internal use only
- #validity_message private Internal use only
BeHelpers
- Included
BaseMatcher
- Inherited
#actual_formatted, | |
#description | Generates a description using |
#expected_formatted, | |
#match_unless_raises | Used to wrap a block of code that will indicate failure by raising one of the named exceptions. |
#matches? | Indicates if the match is successful. |
BaseMatcher::DefaultFailureMessages
- Included
#failure_message | Provides a good generic failure message. |
#failure_message_when_negated | Provides a good generic negative failure message. |
BaseMatcher::StringEncodingFormatting
- Included
#format_encoding | Formats a String’s encoding as a human readable string :nocov: |
BaseMatcher::HashFormatting
- Included
#improve_hash_formatting | ‘{ |
::RSpec::Matchers::Composable
- Included
#& | Alias for Composable#and. |
#=== | Delegates to #matches?. |
#and | Creates a compound |
#description_of | Returns the description of the given object in a way that is aware of composed matchers. |
#or | Creates a compound |
#values_match? | This provides a generic way to fuzzy-match an expected value against an actual value. |
#| | Alias for Composable#or. |
#should_enumerate? | We should enumerate arrays as long as they are not recursive. |
#surface_descriptions_in | Transforms the given data structure (typically a hash or array) into a new data structure that, when |
#unreadable_io?, | |
#with_matchers_cloned | Historically, a single matcher instance was only checked against a single value. |
Instance Attribute Details
#predicate_accessible? ⇒ Boolean
(readonly, private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 68
def predicate_accessible? really_responds_to?(predicate) end
#private_predicate? ⇒ Boolean
(readonly, private)
:nocov:
See additional method definition at line 75.
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 84
def private_predicate? @actual.private_methods.include? predicate.to_s end
Instance Method Details
#description ⇒ String
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 43
def description "#{method_description}#{args_to_sentence}" end
#does_not_match?(actual, &block) ⇒ Boolean
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 23
def does_not_match?(actual, &block) @actual = actual @block ||= block predicate_accessible? && predicate_matches?(false) end
#expectation_of(value) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 126
def expectation_of(value) if RSpec::Expectations.configuration.strict_predicate_matchers? "return #{value}" elsif value "be truthy" else "be falsey" end end
#failure_message ⇒ String
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 31
def (true) end
#failure_message_expecting(value) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 121
def (value) || "expected `#{actual_formatted}.#{predicate}#{args_to_s}` to #{expectation_of value}, got #{description_of @predicate_result}" end
#failure_message_when_negated ⇒ String
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 37
def (false) end
#failure_to_respond_explanation (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 142
def failure_to_respond_explanation if private_predicate? " but `#{predicate}` is a private method" end end
#matches?(actual, &block) ⇒ Boolean
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 16
def matches?(actual, &block) @actual = actual @block ||= block predicate_accessible? && predicate_matches? end
#method_description (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 117
def method_description EnglishPhrasing.split_words(@method_name) end
#methods_include?(method) (private)
See additional method definition at line 79.
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 88
def methods_include?(method) @actual.methods.include?(method.to_s) end
#predicate_matches?(value = true) ⇒ Boolean
(private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 101
def predicate_matches?(value=true) if RSpec::Expectations.configuration.strict_predicate_matchers? value == predicate_result else value == !!predicate_result end end
#predicate_method_name (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 97
def predicate_method_name predicate end
#predicate_result (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 93
def predicate_result @predicate_result = actual.__send__(predicate_method_name, *@args, &@block) end
#really_responds_to?(method) ⇒ Boolean
(private)
:nocov:
# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 62
def really_responds_to?(method) if RSpec::Mocks::Double === @actual @actual.respond_to?(method) && methods_include?(method) else @actual.respond_to?(method) end end
#root (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 109
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
#validity_message (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/has.rb', line 136
def return nil if predicate_accessible? "expected #{actual_formatted} to respond to `#{predicate}`#{failure_to_respond_explanation}" end