Class: RSpec::Matchers::BuiltIn::Compound Private
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
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/compound.rb |
Overview
Base class for and
and or
compound matchers.
Constant Summary
BaseMatcher
- Inherited
Class Method Summary
- .new(matcher_1, matcher_2) ⇒ Compound constructor Internal use only
BaseMatcher
- Inherited
.matcher_name, .new, | |
.underscore | Borrowed from ActiveSupport. |
Instance Attribute Summary
- #diffable? ⇒ Boolean readonly Internal use only
- #evaluator readonly Internal use only
- #expects_call_stack_jump? ⇒ Boolean readonly Internal use only
- #matcher_1 readonly Internal use only
- #matcher_2 readonly Internal use only
- #supports_block_expectations? ⇒ Boolean readonly Internal use only
- #supports_value_expectations? ⇒ Boolean readonly Internal use only
- #matcher_1_matches? ⇒ Boolean readonly private Internal use only
- #matcher_2_matches? ⇒ Boolean readonly private Internal use only
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) ⇒ Boolean Internal use only
- #expected ⇒ RSpec::Matchers::MultiMatcherDiff Internal use only
- #diffable_matcher_list protected Internal use only
- #compound_failure_message private Internal use only
- #diffable_matcher_list_for(matcher) private Internal use only
- #indent_multiline_message(message) private Internal use only
- #initialize_copy(other) private Internal use only
- #match(_expected, actual) private Internal use only
- #matcher_is_diffable?(matcher) ⇒ Boolean private Internal use only
- #matcher_supports_block_expectations?(matcher) ⇒ Boolean private Internal use only
- #matcher_supports_value_expectations?(matcher) ⇒ Boolean private Internal use only
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 |
#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
#diffable? ⇒ Boolean
(readonly)
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 49
def diffable? matcher_is_diffable?(matcher_1) || matcher_is_diffable?(matcher_2) end
#evaluator (readonly)
[ GitHub ]
#expects_call_stack_jump? ⇒ Boolean
(readonly)
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 42
def expects_call_stack_jump? NestedEvaluator.matcher_expects_call_stack_jump?(matcher_1) || NestedEvaluator.matcher_expects_call_stack_jump?(matcher_2) end
#matcher_1 (readonly)
[ GitHub ]
#matcher_1_matches? ⇒ Boolean
(readonly, private)
#matcher_2 (readonly)
[ GitHub ]
#matcher_2_matches? ⇒ Boolean
(readonly, private)
#supports_block_expectations? ⇒ Boolean
(readonly)
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 30
def supports_block_expectations? matcher_supports_block_expectations?(matcher_1) && matcher_supports_block_expectations?(matcher_2) end
#supports_value_expectations? ⇒ Boolean
(readonly)
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 36
def supports_value_expectations? matcher_supports_value_expectations?(matcher_1) && matcher_supports_value_expectations?(matcher_2) end
Instance Method Details
#compound_failure_message (private)
[ GitHub ]
#description ⇒ String
#diffable_matcher_list (protected)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 62
def diffable_matcher_list list = [] list.concat(diffable_matcher_list_for(matcher_1)) unless matcher_1_matches? list.concat(diffable_matcher_list_for(matcher_2)) unless matcher_2_matches? list end
#diffable_matcher_list_for(matcher) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 128
def diffable_matcher_list_for(matcher) return [] unless matcher_is_diffable?(matcher) return matcher.diffable_matcher_list if Compound === matcher [matcher] end
#does_not_match?(_actual) ⇒ Boolean
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 16
def does_not_match?(_actual) raise NotImplementedError, "`expect(...).not_to matcher.#{conjunction} matcher` " \ "is not supported, since it creates a bit of an ambiguity. Instead, define negated versions " \ "of whatever matchers you wish to negate with `RSpec::Matchers.define_negated_matcher` and " \ "use `expect(...).to matcher.#{conjunction} matcher`." end
#expected ⇒ RSpec::Matchers::MultiMatcherDiff
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 55
def expected return nil unless evaluator ::RSpec::Matchers::MultiMatcherDiff.for_many_matchers(diffable_matcher_list) end
#indent_multiline_message(message) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 90
def ( ) .lines.map do |line| line =~ /\S/ ? ' ' + line : line end.join end
#initialize_copy(other) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 71
def initialize_copy(other) @matcher_1 = @matcher_1.clone @matcher_2 = @matcher_2.clone super end
#match(_expected, actual) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 77
def match(_expected, actual) evaluator_klass = if supports_block_expectations? && Proc === actual NestedEvaluator elsif supports_value_expectations? SequentialEvaluator else # Can't raise an ArgumentError in this context, as it's rescued raise "Block and value matchers can't be combined in a compound expectation (#{matcher_1.description}, #{matcher_2.description})" end @evaluator = evaluator_klass.new(actual, matcher_1, matcher_2) end
#matcher_is_diffable?(matcher) ⇒ Boolean
(private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 122
def matcher_is_diffable?(matcher) matcher.diffable? rescue NoMethodError false end
#matcher_supports_block_expectations?(matcher) ⇒ Boolean
(private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 110
def matcher_supports_block_expectations?(matcher) matcher.supports_block_expectations? rescue NoMethodError false end
#matcher_supports_value_expectations?(matcher) ⇒ Boolean
(private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/compound.rb', line 116
def matcher_supports_value_expectations?(matcher) matcher.supports_value_expectations? rescue NoMethodError true end