Method: RSpec::Matchers::DSL#define

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

#define(name) {|Object| ... } ⇒ Object Also known as: matcher

Defines a custom matcher.

Parameters:

  • name (Symbol)

    the name for the matcher

Yields:

  • (Object)

    block that is used to define the matcher. The block is evaluated in the context of your custom matcher class. When args are passed to your matcher, they will be yielded here, usually representing the expected value(s).

See Also:



73
74
75
76
77
78
# File 'lib/rspec/matchers/dsl.rb', line 73

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