-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
match matcher not invoked correctly from custom matchers #188
Comments
AnalysisRSpec::Matchers.define :match_string do
# block A
match do |m|
# block B
expect(m).to match(/in it/)
end
end When defining a custom matcher via When you call those matchers in your spec (i.e. So when executing the In your example, block B itself calls a method If we were to inspect the ancestor tree right before the $ method(:match).source_location
=> ["/Users/steven/code/rspec-dev/repos/rspec-expectations/lib/rspec/matchers/matcher.rb",
$ self.class.ancestors
=> [RSpec::Matchers::DSL::Matcher,
RSpec::Matchers,
RSpec::Matchers::Pretty,
RSpec::Matchers::Extensions::InstanceEvalWithArgs,
Object,
PP::ObjectMixin,
Kernel,
BasicObject,
RSpec::Mocks::Methods] Possible solutionWe could |
Addresses problem with dispatching the #match matcher from within a custom matcher. (Wow... what a mouthful) See Issue rspec#188.
@hgmnz -- give @stevenharman's fix (now in master) a try. It should solve your problem. |
@myronmarston yup, this works for me. Like the simple solution, too. Thanks @stevenharman! |
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
When the
match
matcher is used within a custom matcher, it is invoking the wrong method.A simple case to reproduce:
which when run, gives:
This issue was originally reported at rspec/rspec-core#725
The text was updated successfully, but these errors were encountered: