-
-
Notifications
You must be signed in to change notification settings - Fork 753
(refactor): Avoid calling superclass.method #2112
Conversation
Thanks, @dgmstuart! Do you mind adding a spec for this to ensure we don't regress in the future? As it is, someone could submit a PR with a refactoring back to using |
I think so. I was thinking of this as a straight refactoring, but on reflection that's not the case. On Tue, Nov 10, 2015 at 3:57 PM, Myron Marston [email protected]
|
@myronmarston Here's what I've tried - not working # spec/rspec/core/example_group_spec.rb
it "doesn't conflict with subclasses which override `.method`" do
# see https://github.com/rspec/rspec-core/issues/2008
group = RSpec.describe('group') do
shared_examples_for("outer") do
def self.method(arg)
fail StandardError, "Unexpected call"
end
shared_examples_for("inner") do
example('ex 1') { expect(1).to eq(1) }
end
it_should_behave_like "inner"
end
it_should_behave_like "outer"
end
expect{ group.run }.to_not raise_error
end I'm not 100% sure I understand how the specs in that file work: the call to |
This works and is quite a bit simpler than what you have: it 'allows extensions to add `method` to the DSL without causing problems' do
http_testing_extension = Module.new do
attr_reader :http_method
def method(meth); @http_method = meth; end
end
describe_successfully do
extend http_testing_extension
method :get
it "allows `method` to specify the HTTP method" do
expect(self.class.http_method).to eq(:get)
end
end
end ( Note that this spec fails with your change -- because a similar change has to be made in another place. Without a spec we wouldn't have realized that! |
@myronmarston so many thanks for this - I'll get on it when I can. |
@dgmstuart Hi! Are you still able to work on this? I'd love to see it merged. |
Yes! Sorry - I do plan to and its on my list. Are you planning a release or just checking the PR isn't stale? On Thu, Dec 10, 2015 at 2:01 PM, Sam Phippen [email protected]
|
@dgmstuart just doing staleness checks. Are you likely to be able to push the commits to finish this off within the next week? |
Yes I'll commit to that :) On Thu, Dec 10, 2015 at 9:52 PM, Sam Phippen [email protected]
|
So here's where I've got to: @myronmarston's spec above covers the additional case in normal example groups (now covered in This is covered by dgmstuart@3a586e1), but doesn't seem to cover the shared example groups case: it doesn't fail when I've tried to add a corresponding spec for shared example groups in 4156907 but it raises an error relating to exception presentation:
This code gets called three times (??) and chokes when the
...because I'm not sure where to start in understanding this: It's probably an issue with my spec, but also potentially this scenario could be raising a more meaningful exception earlier (?): I don't really understand what this code is doing, but clearly it's never expecting the child and parent to have identical backtraces. Looks like Can anyone point me in the right direction? (@samphippen?) |
OK, extremely confused now - on Travis it's actually failing with an apparently unrelated error, and when running the whole suite locally, the spec fails in the documentation output as it's going through, but doesn't show an error at the end :( |
@dgmstuart you may want to try rebasing against master, and see if that helps. |
4156907
to
8ac1f69
Compare
@samphippen rebased - same test output, but I realised I was reading it wrong: Travis correctly shows one failure, but the output at the end of the rspec run doesn't include that failure - just the output for the pending specs. Running the Not sure I can make any more progress without help: this |
@dgmstuart I'll take a look at this for you now. |
I think I've worked out the root cause here. It's going to require me to do a little more investigation. @dgmstuart are you ok waiting on a patch from me before continuing? |
Absolutely. Thanks so much :) On Sun, Dec 13, 2015 at 5:47 PM, Sam Phippen [email protected]
|
@myronmarston I need some help here. With this branch applied, when @dgmstuart's test fails we generate a backtrace which has the same parent and child exception in the CommonBacktraceTruncator. This causes I have tried:
Both cause an entertaining infinite recursion bug. I've tried debugging the infinite recursion bug, but I can't seem to squash it. Any thoughts? |
…o the list of `all_exceptions` This was exposed by #2112 which contains a spec which uses `describe_successfully` which seems to somehow add the existing `MultipleExceptionError` to itself when it fails. This **does not happen** if the example passes (presumably because an error is not generated). When we format the exception [here](https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/exception_presenter.rb#L330) we use FlatMap, which is going to continuously unpack the exception, causing infinite recursion. This patch prevents `MultipleExceptionError::InterfaceTag#add` from allowing `self` to be included in the `all_exceptions` array. This fixes the problem. As far as I can tell from running our suite, the `self` being added case never actually happens during normal RSpec execution and so adding this is fine. I added a spec which demonstrates this behaviour in case that turns out to be problematic in the future. I can't imagine that happening though as this will precisely cause the same infinite recursion bug.
…o the list of `all_exceptions` This was exposed by #2112 which contains a spec which uses `describe_successfully` which seems to somehow add the existing `MultipleExceptionError` to itself when it fails. This **does not happen** if the example passes (presumably because an error is not generated). When we format the exception [here](https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/exception_presenter.rb#L330) we use FlatMap, which is going to continuously unpack the exception, causing infinite recursion. This patch prevents `MultipleExceptionError::InterfaceTag#add` from allowing `self` to be included in the `all_exceptions` array. This fixes the problem. As far as I can tell from running our suite, the `self` being added case never actually happens during normal RSpec execution and so adding this is fine. I added a spec which demonstrates this behaviour in case that turns out to be problematic in the future. I can't imagine that happening though as this will precisely cause the same infinite recursion bug.
@myronmarston further to my previous I've opened #2133 but I'd really like your eyes on it before we merge. Would you mind taking a look? @dgmstuart in the mean time, you can base your PR on top of the branch I pushed in #2133 to keep this one going. |
@dgmstuart I just merged that pull request, so you should be good to rebase off master and continue working on this. |
...in favour of using a lambda. This addresses rspec#2008 But really, any third party code which causes problems with the original code is probably doing something a bit dodgy (e.g. overriding the `method` method on an object).
Without this a `NoMethodError` is raised: undefined method `call' for :next_runnable_index_for:Symbol
8ac1f69
to
dd42024
Compare
Great! Thanks @samphippen. Rebasing now. Just for my curiosity, is the case which your PR fixes only happening when RSpec is testing itself, and not in a normal use case? |
@dgmstuart as far as I can tell, it's an RSpec testing RSpec problem |
Currently failing :(
dd42024
to
a9ea58b
Compare
@dgmstuart I'm going to close this because it's been stale since December. If you'd like to pick this up again, feel free to re-open and push new commits. |
…o the list of `all_exceptions` This was exposed by rspec#2112 which contains a spec which uses `describe_successfully` which seems to somehow add the existing `MultipleExceptionError` to itself when it fails. This **does not happen** if the example passes (presumably because an error is not generated). When we format the exception [here](https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/exception_presenter.rb#L330) we use FlatMap, which is going to continuously unpack the exception, causing infinite recursion. This patch prevents `MultipleExceptionError::InterfaceTag#add` from allowing `self` to be included in the `all_exceptions` array. This fixes the problem. As far as I can tell from running our suite, the `self` being added case never actually happens during normal RSpec execution and so adding this is fine. I added a spec which demonstrates this behaviour in case that turns out to be problematic in the future. I can't imagine that happening though as this will precisely cause the same infinite recursion bug.
...in favour of using a lambda.
This addresses #2008
But really, any third party code which causes problems with the original
code is probably doing something a bit dodgy (e.g. overriding the
method
method on anobject).
Core test suite passes locally, but I haven't been able to run the travis build locally because of the following (unrelated) error:
(I'm using bundler 1.10.6)