class RSpec::Matchers::BuiltIn::Compound

@api private Base class for ‘and` and `or` compound matchers.

Attributes

Public Class Methods

# File rspec-expectations/lib/rspec/matchers/built_in/compound.rb, line 10
def initialize(matcher_1, matcher_2)
  @matcher_1 = matcher_1
  @matcher_2 = matcher_2
end

Public Instance Methods

@api private @return [String]

# File rspec-expectations/lib/rspec/matchers/built_in/compound.rb, line 25
def description
  "#{matcher_1.description} #{conjunction} #{matcher_2.description}"
end

@api private @return [Boolean]

# 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

@private

# 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

@api private @return [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

@api private

# 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

@api private

# 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

@api private

# 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

Protected Instance Methods

# 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