Method: RSpec::Matchers::DSL#define_negated_matcher

Defined in:
lib/rspec/matchers/dsl.rb

#define_negated_matcher(negated_name, base_name) {|String| ... } ⇒ Object

Defines a negated matcher. The returned matcher's description and failure_message will be overridden to reflect the phrasing of the new name, and the match logic will be based on the original matcher but negated.

Examples:

RSpec::Matchers.define_negated_matcher :exclude, :include
include(1, 2).description # => "include 1 and 2"
exclude(1, 2).description # => "exclude 1 and 2"

Parameters:

  • negated_name (Symbol)

    the name for the negated matcher

  • base_name (Symbol)

    the name of the original matcher that will be negated

Yields:

  • (String)

    optional block that, when given, is used to define the overridden logic. The yielded arg is the original description or failure message. If no block is provided, a default override is used based on the old and new names.

See Also:



61
62
63
# File 'lib/rspec/matchers/dsl.rb', line 61

def define_negated_matcher(negated_name, base_name, &description_override)
  alias_matcher(negated_name, base_name, :klass => AliasedNegatedMatcher, &description_override)
end