-
-
Notifications
You must be signed in to change notification settings - Fork 1k
LetDefinitions needs to be defined on the nested instance rather than the definition of ExampleGroup #738
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
LetDefinitions needs to be defined on the nested instance rather than the definition of ExampleGroup #738
Conversation
I suspect this is the source of #737 as well. |
:( Help wanted here, though I'll try to dig in soon. |
I think I just realized what the problem is. It's actually not rspec-rails specific, but it is exacerbated by all the modules rspec rails mixes in to provide helper methods. In 2.13, we changed how As a result, if a The question is, what should we do about it? I think it would be very complicated to make the user's Thoughts? |
@myronmarston As I said over on rspec/rspec-core#817 the problem is the ordering of the example group ancestors particularly the let definition module vs the helper modules. On pure I believe that the problem you outlined with |
Can you point me to the code that changes the order of the ancestors? I don't understand this. |
@myronmarston That's what I need help with, I can't seem to find any that would do it. See https://gist.github.com/JonRowe/5368859 for the changes |
OK, I think I see what's going on here, but I'm going to leave some raw analysis for @JonRowe and @myronmarston ... and revisit it myself in the morning as my brain is shot for the night :) Many Rails example groups define That said, calling Because |
I'm going to try an experiment in rspec-core where I try to defer the inclusion of the module that defines Again, thanks so much for this test case. It's helped me very quickly understand what was happening. |
@alindeman -- that sounds worthwhile. I commented above about this, but do you think it would also be worthwhile to raise an error and/or print a warning if |
…rative method There is currently some odd interactions between rspec-rails and rspec-core when it comes to `let` definitions. If we call `subject` in an `included` hook, the dynamically generated `LetDefinitions` module gets inserted into the ancestor chain earlier than normal. This placement no longer allows `let` definitions to override methods defined on other modules that are brought in via `config.include`. We may raise a warning in future (see discussion in #738) [Fixes #738]
@myronmarston, I have a feeling that many folks may depend on the ability to override methods via I have pushed a fix that uses a method named Notably, I believe it is still possible to cause weird behavior without |
…ample_group_instance LetDefinitions needs to be defined on the nested instance rather than the definition of ExampleGroup
…rative method There is currently some odd interactions between rspec-rails and rspec-core when it comes to `let` definitions. If we call `subject` in an `included` hook, the dynamically generated `LetDefinitions` module gets inserted into the ancestor chain earlier than normal. This placement no longer allows `let` definitions to override methods defined on other modules that are brought in via `config.include`. We may raise a warning in future (see discussion in #738) [Fixes #738] Conflicts: Changelog.md
I've merged this for now, but feel free to keep the discussion going here or elsewhere. |
I feel that's a definite |
It's on my TODO to make a test case and file a bug against rspec-core. |
FWIW, I've got some thoughts on how to fix this in core. |
This is confusing and not useful as documentation, all #738 was intended to do was to prevent our let definitions from being defined earlier than 3rd party inclusions (and hence being overriden) which was confusing behaviour, so move it to a spec.
Move #738 regression check to spec
This is confusing and not useful as documentation, all rspec#738 was intended to do was to prevent our let definitions from being defined earlier than 3rd party inclusions (and hence being overriden) which was confusing behaviour, so move it to a spec.
In
v2.13.0
let
defintion withrspec-rails
is broken when shadowing definitions in helper modules.In
rspec-core
the blocks passed tolet
generate methods on aLetDefinitions
module (see here), which is delegated to by the memoization. Withrspec-rails
these definitions are occurring on a top levelExampleGroup::LetDefintions
module rather than being defined on the anonymous nested instances. This means that helper methods which shadow the let name will be memozied instead of the let's block.The symptom of this originally popped up in
rspec-core
(rspec/rspec-core#817) but I was unable to replicate it withoutrspec-rails
so I believe the issue lies here. Alternatively we need to change how we define let's again.I've created this branch on
rspec-rails
rather than my fork because I need feedback on how this could be occurring, I'm not familiar enough with the internals. The feature attached is not expected to be included in any final patch, it's just for demonstation of the problem.So... Thoughts? @alindeman @samphippen ...