-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
Bugfix: makes possible to use RSpec::Matchers#include inside a custom matcher definition #272
Conversation
…matcher That bug was happening because RSpec::Matchers::DSL::Matcher has a `include` private method that was overriding the `include` method include from RSpec::Matchers.
@hugobarauna -- thanks for digging into this bug and providing a fix. We should definitely address this. However, there's a case that your fix won't solve: RSpec::Matchers.define :descend_from do |module|
match do |klass|
expect(klass.ancestors).to include(module)
end
end
expect(my_class).to descend_from(some_module) I think we need to figure out a better way to detect |
@myronmarston Tks for the fast answer! I understood the problem with my solution and I would like to fix it. After your feedback I already invested one hour trying to come up with a clever solution for the problem, but I was not able to come up with anything. 😢. So, do you think you can point me a direction here? [off-topic] The parts on the codebase that I'm having more difficulty to understand are the ones using a lot of context manipulation ( |
@myronmarston I (think) I fixed the problem you pointed, but I didn't like that much the solution, it doesn't seen elegant. Besides that problem, I'm not sure using a instance variable for signaling if the |
@hugobarauna -- unfortunately, this isn't an easy issue to solve :(. I'm going to have to spend some more time with it before I can come up with a suggestion for how to fix it. You're right about the custom matcher definition being confusing. We may try to refactor it in 3.0 to not be quite as convoluted. |
Ok, if you think it's worth explaining to me a solution so to that I can code it, go for it, I would be very happy to help. But if you think this bug is too hard for a newcomer in rspec's codebase as I am, there's no problem too. |
After mulling this over overnight, I'm thinking the best way to solve this is to change the way customer matchers are defined, so that rather than the main I think the reason it's not already defining a class in this fashion is because you would normally want to eval the Regardless, this is going to be a big enough change that I think we'll hold off until 3.0 for it. Thoughts? |
Sorry for the delay, it's a lof of information. Unfortunately, I think I'll have the time to process that only during the mid of the next week. :( |
That's fine. If you want to give it a shot later when you have the time, feel free -- that said, it's a pretty major refactoring, and something that would be pretty difficult for someone who hasn't worked with the rspec codebase much yet. So feel free to leave it to one of us -- I'll probably get to it at some point. At this point, I'm slating this for 3.0, so there's not a huge rush to get it in soon. |
@hugobarauna -- I rewrote the custom matcher DSL in #332 to solve this problem (among others). I also tried to make it much less confusing. Can you take a look and let me know what you think? Anyhow, I'm going to close this, now that we have that as a better solution. I used your spec, though :). |
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 PR introduces a bugfix. That bug was happening because
RSpec::Matchers::DSL::Matcher
has ainclude
private method that was overriding theinclude
method included fromRSpec::Matchers
. (I know, too much include words in just one phrase =p)I got that problem while trying to write the following custom matcher:
I think this is a bug because it is part of the spec of
RSpec::Matchers::DSL::Matcher
to allow us to use the built-in matchers inside a custom matcher definition.