mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Fix a bug where Pry::Config.new(nil) == nil
would return true. (#1903)
This commit is contained in:
parent
b5538b8501
commit
54e6ce52f7
2 changed files with 29 additions and 21 deletions
|
@ -215,6 +215,8 @@ class Pry
|
||||||
# True if self and `other` are considered `eql?`, otherwise false.
|
# True if self and `other` are considered `eql?`, otherwise false.
|
||||||
#
|
#
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
return false if !other
|
||||||
|
|
||||||
@lookup == __try_convert_to_hash(other)
|
@lookup == __try_convert_to_hash(other)
|
||||||
end
|
end
|
||||||
alias_method :eql?, :==
|
alias_method :eql?, :==
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
describe Pry::Config do
|
RSpec.describe Pry::Config do
|
||||||
|
describe ".from_hash" do
|
||||||
|
it "returns an object without a default" do
|
||||||
|
local = described_class.from_hash({})
|
||||||
|
expect(local.default).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an object with a default" do
|
||||||
|
default = described_class.new(nil)
|
||||||
|
local = described_class.from_hash({}, default)
|
||||||
|
expect(local.default).to eq(local)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "recursively creates Pry::Config objects from a Hash" do
|
||||||
|
h = {'foo1' => {'foo2' => {'foo3' => 'foobar'}}}
|
||||||
|
default = described_class.from_hash(h)
|
||||||
|
expect(default.foo1).to be_instance_of(described_class)
|
||||||
|
expect(default.foo1.foo2).to be_instance_of(described_class)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "bug #1552" do
|
describe "bug #1552" do
|
||||||
specify "a local key has precendence over its default when the stored value is false" do
|
specify "a local key has precendence over its default when the stored value is false" do
|
||||||
local = described_class.from_hash({}, described_class.from_hash('color' => true))
|
local = described_class.from_hash({}, described_class.from_hash('color' => true))
|
||||||
|
@ -53,26 +73,6 @@ describe Pry::Config do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".from_hash" do
|
|
||||||
it "returns an object without a default" do
|
|
||||||
local = described_class.from_hash({})
|
|
||||||
expect(local.default).to eq(nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns an object with a default" do
|
|
||||||
default = described_class.new(nil)
|
|
||||||
local = described_class.from_hash({}, default)
|
|
||||||
expect(local.default).to eq(local)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "recursively creates Pry::Config objects from a Hash" do
|
|
||||||
h = {'foo1' => {'foo2' => {'foo3' => 'foobar'}}}
|
|
||||||
default = described_class.from_hash(h)
|
|
||||||
expect(default.foo1).to be_instance_of(described_class)
|
|
||||||
expect(default.foo1.foo2).to be_instance_of(described_class)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#respond_to_missing?" do
|
describe "#respond_to_missing?" do
|
||||||
before do
|
before do
|
||||||
@config = described_class.new(nil)
|
@config = described_class.new(nil)
|
||||||
|
@ -140,6 +140,12 @@ describe Pry::Config do
|
||||||
local1 = described_class.new(nil)
|
local1 = described_class.new(nil)
|
||||||
expect(local1).not_to eq(Object.new)
|
expect(local1).not_to eq(Object.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns false when compared against nil" do
|
||||||
|
# rubocop:disable Style/NilComparison
|
||||||
|
expect(described_class.new(nil) == nil).to eq(false)
|
||||||
|
# rubocop:enable Style/NilComparison
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#forget" do
|
describe "#forget" do
|
||||||
|
|
Loading…
Reference in a new issue