class RSpec::Matchers::AliasedNegatedMatcher

@private

def does_not_match?(*args, &block)

def does_not_match?(*args, &block)
  @base_matcher.matches?(*args, &block)
end

def failure_message

def failure_message
  optimal_failure_message(__method__, :failure_message_when_negated)
end

def failure_message_when_negated

def failure_message_when_negated
  optimal_failure_message(__method__, :failure_message)
end

def matches?(*args, &block)

def matches?(*args, &block)
  if @base_matcher.respond_to?(:does_not_match?)
    @base_matcher.does_not_match?(*args, &block)
  else
    !super
  end
end

def optimal_failure_message(same, inverted)

the non-negated failure message for a negated match (or vice versa).
message is going to be confusing if we return it as-is, as it represents
should return the opposite failure message instead -- the overridden
However, if the override didn't actually change anything, then we

by going through the effort of defining a negated matcher.
includes the phrasing that the user has expressed a preference for
use the override provided by the `description_block`, because it
For a matcher that uses the default failure messages, we prefer to
def optimal_failure_message(same, inverted)
  if DefaultFailureMessages.has_default_failure_messages?(@base_matcher)
    base_message = @base_matcher.__send__(same)
    overridden    = @description_block.call(base_message)
    return overridden if overridden != base_message
  end
  @base_matcher.__send__(inverted)
end