Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define method in matcher dsl #29

Closed

Conversation

myronmarston
Copy link
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.

@myronmarston
Copy link
Member Author

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 pushed a commit to eloyesp/rspec-expectations that referenced this pull request Nov 5, 2013
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
  match).
* 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:
  rspec#29,
  rspec#38,
  rspec@fc4b66d
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant