Skip to content

Define method in matcher dsl #29

wants to merge 0 commits into from

1 participant

RSpec member

On several occasions, when writing a helper method in a custom matcher I've defined using the matcher DSL, I've wanted to define the method using #define_method so that it has access to the matcher parameters (such as expected). Currently I get a NoMethodError when I do this.

My commit fixes this by delegating define_method to the matcher's singleton class.

RSpec member

Delegate Matcher#define_method to its singleton class.

This allows you to define helper methods in a matcher using #define_method to gain access to the parameters.

@eloyesp eloyesp pushed a commit to eloyesp/rspec-expectations that referenced this pull request Nov 5, 2013
@myronmarston myronmarston Rewrite custom matcher DSL.
Rather than evaling the `define` block in the
context of the matcher instance, eval the `define`
block in the context of the matcher instance's
singleton class.

* Fixes rspec#272.
  `include` in `define` has a different meaning (module inclusion)
  than `include` in the `match` block (using the `include` matcher to
* Better solution than rspec#194
  for rspec#188. There's now
  a `match` class method and a `match` instance method.
* Completely avoids issues we had to use hacks to solve before:
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.