diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2020-03-21 16:16:38 +0800 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2020-03-21 16:53:58 +0800 |
commit | ff6567d3f435d7519d1e5d26fbeff18dc537456e (patch) | |
tree | 7204a87da7080da63ba3115312f88509d1fb4064 /spec | |
parent | 36c7fdbc48ec0b81809e7f28e4df0fa3c9a4a4fa (diff) | |
download | pry-ff6567d3f435d7519d1e5d26fbeff18dc537456e.tar.gz |
method: delegate internally-used methods
Improves on #2086 (Directly delegate internally-used Method methods)
(we add tests here)
Description by @michaelherold
> Relying on `method_missing` for all delegation to `Method` methods means
> that it's easier for the wrong method to be called when gems mess with
> `Object` or other such core areas.
> See https://github.com/ankane/ownership/pull/3 for an example of this.
> By defining explicit delegators, at least for the methods that we use
> internally withing Pry, we can eliminate this issue and be more
> communicative around the methods on the `Pry::Method` class.
I omitted the `source_location` changes because they need some clarification.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/method_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 65ce0e96..95ac075c 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -658,4 +658,67 @@ describe Pry::Method do end end end + + describe "#owner" do + context "when it is overriden in Object" do + before do + module OwnerMod + def owner + :fail + end + end + + Object.__send__(:include, OwnerMod) + end + + after { Object.remove_const(:OwnerMod) } + + it "correctly reports the owner" do + method = described_class.new(method(:puts)) + expect(method.owner).not_to eq(:fail) + end + end + end + + describe "#parameters" do + context "when it is overriden in Object" do + before do + module ParametersMod + def parameters + :fail + end + end + + Object.__send__(:include, ParametersMod) + end + + after { Object.remove_const(:ParametersMod) } + + it "correctly reports the parameters" do + method = described_class.new(method(:puts)) + expect(method.parameters).not_to eq(:fail) + end + end + end + + describe "#receiver" do + context "when it is overriden in Object" do + before do + module ReceiverMod + def receiver + :fail + end + end + + Object.__send__(:include, ReceiverMod) + end + + after { Object.remove_const(:ReceiverMod) } + + it "correctly reports the receiver" do + method = described_class.new(method(:puts)) + expect(method.receiver).not_to eq(:fail) + end + end + end end |