class RSpec::Matchers::BuiltIn::Compound
Base class for ‘and` and `or` compound matchers.
@api private
def compound_failure_message
def compound_failure_message "#{indent_multiline_message(matcher_1.failure_message.sub(/\n+\z/, ''))}" \ "\n\n...#{conjunction}:" \ "\n\n#{indent_multiline_message(matcher_2.failure_message.sub(/\A\n+/, ''))}" end
def description
-
(String)
-
Other tags:
- Api: - private
def description "#{matcher_1.description} #{conjunction} #{matcher_2.description}" end
def diffable?
-
(Boolean)
-
Other tags:
- Api: - private
def diffable? matcher_is_diffable?(matcher_1) || matcher_is_diffable?(matcher_2) end
def diffable_matcher_list
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
def diffable_matcher_list_for(matcher)
def diffable_matcher_list_for(matcher) return [] unless matcher_is_diffable?(matcher) return matcher.diffable_matcher_list if Compound === matcher [matcher] end
def does_not_match?(_actual)
- Private: -
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
def expected
-
(RSpec::Matchers::MultiMatcherDiff)
-
Other tags:
- Api: - private
def expected return nil unless evaluator ::RSpec::Matchers::MultiMatcherDiff.for_many_matchers(diffable_matcher_list) end
def expects_call_stack_jump?
- Api: - private
def expects_call_stack_jump? NestedEvaluator.matcher_expects_call_stack_jump?(matcher_1) || NestedEvaluator.matcher_expects_call_stack_jump?(matcher_2) end
def indent_multiline_message(message)
def indent_multiline_message(message) message.lines.map do |line| line =~ /\S/ ? ' ' + line : line end.join end
def initialize(matcher_1, matcher_2)
def initialize(matcher_1, matcher_2) @matcher_1 = matcher_1 @matcher_2 = matcher_2 end
def initialize_copy(other)
def initialize_copy(other) @matcher_1 = @matcher_1.clone @matcher_2 = @matcher_2.clone super end
def match(_expected, actual)
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
def matcher_1_matches?
def matcher_1_matches? evaluator.matcher_matches?(matcher_1) end
def matcher_2_matches?
def matcher_2_matches? evaluator.matcher_matches?(matcher_2) end
def matcher_is_diffable?(matcher)
def matcher_is_diffable?(matcher) matcher.diffable? rescue NoMethodError false end
def matcher_supports_block_expectations?(matcher)
def matcher_supports_block_expectations?(matcher) matcher.supports_block_expectations? rescue NoMethodError false end
def matcher_supports_value_expectations?(matcher)
def matcher_supports_value_expectations?(matcher) matcher.supports_value_expectations? rescue NoMethodError true end
def supports_block_expectations?
- Api: - private
def supports_block_expectations? matcher_supports_block_expectations?(matcher_1) && matcher_supports_block_expectations?(matcher_2) end
def supports_value_expectations?
- Api: - private
def supports_value_expectations? matcher_supports_value_expectations?(matcher_1) && matcher_supports_value_expectations?(matcher_2) end