diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb index 150e6bbf..719dd5e6 100644 --- a/lib/pry/config/behavior.rb +++ b/lib/pry/config/behavior.rb @@ -51,7 +51,7 @@ module Pry::Config::Behavior # def [](key) key = key.to_s - @lookup[key] or (@default and @default[key]) + key?(key) ? @lookup[key] : (@default and @default[key]) end # @@ -152,7 +152,7 @@ module Pry::Config::Behavior last = last.default while last and last.default last end - + # # @return [Hash] # returns a duplicate copy of the lookup table used by self. diff --git a/spec/commands/show_doc_spec.rb b/spec/commands/show_doc_spec.rb index 5c8405c0..7b5c6aec 100644 --- a/spec/commands/show_doc_spec.rb +++ b/spec/commands/show_doc_spec.rb @@ -134,17 +134,12 @@ describe "show-doc" do # @param foo def initialize(foo); end } - - begin - t = pry_tester(binding) - expect(t.eval("show-doc _c#initialize")).to match(/_c.new :foo/) - Pry.config.color = true - # I don't want the test to rely on which colour codes are there, just to - # assert that "something" is being colourized. - expect(t.eval("show-doc _c#initialize")).not_to match(/_c.new :foo/) - ensure - Pry.config.color = false - end + t = pry_tester(binding) + expect(t.eval("show-doc _c#initialize")).to match(/_c.new :foo/) + # I don't want the test to rely on which colour codes are there, just to + # assert that "something" is being colourized. + t.eval("_pry_.color = true") + expect(t.eval("show-doc _c#initialize")).not_to match(/_c.new :foo/) end it "should syntax highlight `code` in rdoc" do @@ -155,17 +150,12 @@ describe "show-doc" do def initialize(foo); end } - begin - t = pry_tester(binding) - expect(t.eval("show-doc _c#initialize")).to match(/_c.new\(:foo\)/) - Pry.config.color = true - # I don't want the test to rely on which colour codes are there, just to - # assert that "something" is being colourized. - expect(t.eval("show-doc _c#initialize")).not_to match(/_c.new\(:foo\)/) - ensure - Pry.config.color = false - end - + t = pry_tester(binding) + expect(t.eval("show-doc _c#initialize")).to match(/_c.new\(:foo\)/) + # I don't want the test to rely on which colour codes are there, just to + # assert that "something" is being colourized. + t.eval("_pry_.color = true") + expect(t.eval("show-doc _c#initialize")).not_to match(/_c.new\(:foo\)/) end it "should not syntax highlight `` inside code" do diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 9a4e8f7e..d6961c80 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -1,7 +1,15 @@ require_relative 'helper' describe Pry::Config do + describe "bug #1552" do + specify "a local key has precendence over its default when the stored value is false" do + local = Pry::Config.from_hash({}, Pry::Config.from_hash('color' => true)) + local.color = false + expect(local.color).to eq(false) + end + end + describe "bug #1277" do - specify "a local key has precendence over a inherited method of the same name" do + specify "a local key has precendence over an inherited method of the same name" do local = Pry::Config.from_hash(output: 'foobar') local.extend Module.new { def output(); 'broken'; end } expect(local.output).to eq('foobar')