-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
Provide self
(the instance) to #any_instance blocks
#175
Comments
hrm...I can see how this is useful. I wonder if the instance should go first so you can use Although this brings to mind the discussion in #23 - wonder if some info about the stubbed out object & method should be exposed inside the stub block somehow. |
+1 I really need this functionality and can see how it would be beneficial to others as well |
Obligatory 👍 on this, just spent hours trying to figure out a good way around not having this because Rails filters are evil. |
+1 |
Hey @zettabyte how are you getting along with this? |
@JonRowe: I'm still all for this feature. Early on after I first reported it I attempted an implementation so I could submit a pull request for consideration. However, I'd need to spend more time (than I've had available) to get it to actually work; I'm completely unfamiliar with rspec's code. An aside, every time I see the issue title with the word |
I'd still like to get this in; the hardest part is that if we just change to this it'll be a backwards incompatibility, because the args yielded to the block implementation will change. I think that to make this change we'll have to provide a config option that defaults to off, so it reminds 100% backwards compatible. |
+1 |
2 similar comments
+1 |
+1 |
@myronmarston what about if we evaluated the blocks in the context of the instance, thus making |
Ah ok it was considered before ;) |
+1 |
1 similar comment
+1 |
We're still planning on this for RSpec 3. There's a comment from #236 (which we decided not to merge) that I thought would be useful to quote here so folks know the direction we'll be going with this and the reasons:
|
Yeah for the record, recent experience has taught me that there's no way we should evaluate the blocks so that self is the instance, providing it to the block as an argument is a far better solution both technically and for developer sanity :) |
This has been fixed by @samphippen and will be the default behavior in RSpec 3. |
Feature Request
For both stubs and method expectations on
#any_instance
, where the user provides a block implementation, it would be great if there were a way to get at the actual instance on which the method actually gets called.One possible way would be to include the instance as an extra parameter to the block, at the end of the list, if the
arity
of the block indicates the user's block expects to receive this extra instance parameter (and leave it off otherwise).The text was updated successfully, but these errors were encountered: