module RSpec::Matchers::DSL::Macros
def define_user_override(method_name, user_def, &our_def)
(e.g. assigning `@actual`, rescueing errors, etc) and
an override that can provide the wrapped handling
(e.g. for an early guard statement), while allowing us to define
them to use normal method constructs like `return`
This compiles the user block into an actual method, allowing
as an arg, but only if their block's arity can handle it.
of needing to call the user's definition with `@actual`
- Provides a default `our_def` block for the common case
usign the provided `our_def` block.
- Defines an overridden definition for the same method
in the singleton class in which we eval the `define` block.
in @user_method_defs, which is included as an ancestor
- Defines the named method using a user-provided block
Does the following:
def define_user_override(method_name, user_def, &our_def) @user_method_defs.__send__(:define_method, method_name, &user_def) our_def ||= lambda { super(*actual_arg_for(user_def)) } define_method(method_name, &our_def) end