module RSpec::Matchers::DSL

def alias_matcher(new_name, old_name, options={}, &description_override)

Other tags:
    See: RSpec::Matchers -

Other tags:
    Yield: - optional block that, when given, is used to define the overridden

Options Hash: (**options)
  • :klass (Class) -- the ruby class to use as the decorator. (Not normally used).

Parameters:
  • options (Hash) -- options for the aliased matcher
  • old_name (Symbol) -- the original name for the matcher
  • new_name (Symbol) -- the new name for the matcher
def alias_matcher(new_name, old_name, options={}, &description_override)
  description_override ||= lambda do |old_desc|
    old_desc.gsub(EnglishPhrasing.split_words(old_name), EnglishPhrasing.split_words(new_name))
  end
  klass = options.fetch(:klass) { AliasedMatcher }
  define_method(new_name) do |*args, &block|
    matcher = __send__(old_name, *args, &block)
    matcher.matcher_name = new_name if matcher.respond_to?(:matcher_name=)
    klass.new(matcher, description_override)
  end
  ruby2_keywords new_name if respond_to?(:ruby2_keywords, true)
end

def define(name, &declarations)

Other tags:
    See: RSpec::Matchers -

Other tags:
    Yield: - block that is used to define the matcher.

Parameters:
  • name (Symbol) -- the name for the matcher
def define(name, &declarations)
  warn_about_block_args(name, declarations)
  define_method name do |*expected, &block_arg|
    RSpec::Matchers::DSL::Matcher.new(name, declarations, self, *expected, &block_arg)
  end
end

def define_negated_matcher(negated_name, base_name, &description_override)

Other tags:
    See: RSpec::Matchers -

Other tags:
    Yield: - optional block that, when given, is used to define the overridden

Parameters:
  • base_name (Symbol) -- the name of the original matcher that will be negated
  • negated_name (Symbol) -- the name for the negated matcher
def define_negated_matcher(negated_name, base_name, &description_override)
  alias_matcher(negated_name, base_name, :klass => AliasedNegatedMatcher, &description_override)
end

def warn_about_block_args(name, declarations)

def warn_about_block_args(name, declarations)
  declarations.parameters.each do |type, arg_name|
    next unless type == :block
    RSpec.warning("Your `#{name}` custom matcher receives a block argument (`#{arg_name}`), " \
                  "but due to limitations in ruby, RSpec cannot provide the block. Instead, " \
                  "use the `block_arg` method to access the block")
  end
end

def warn_about_block_args(*)

:nocov:
def warn_about_block_args(*)
  # There's no way to detect block params on 1.8 since the method reflection APIs don't expose it
end