1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/spec/config_spec.rb

80 lines
2.1 KiB
Ruby
Raw Normal View History

2014-01-21 10:32:03 -05:00
require 'helper'
describe Pry::Config do
describe "reserved keys" do
it "raises an ArgumentError on assignment of a reserved key" do
2014-01-30 20:43:13 -05:00
local = Pry::Config.from_hash({})
2014-01-29 19:41:56 -05:00
Pry::Config::RESERVED_KEYS.each do |key|
2014-01-30 20:43:13 -05:00
should.raise(ArgumentError) { local[key] = 1 }
2014-01-29 19:41:56 -05:00
end
end
end
2014-01-30 20:39:23 -05:00
describe "traversal to parent" do
it "traverses back to the parent when a local key is not found" do
2014-01-30 20:43:13 -05:00
local = Pry::Config.new Pry::Config.from_hash(foo: 1)
local.foo.should == 1
2014-01-21 10:32:03 -05:00
end
2014-01-30 20:39:23 -05:00
it "stores a local key and prevents traversal to the parent" do
2014-01-30 20:43:13 -05:00
local = Pry::Config.new Pry::Config.from_hash(foo: 1)
local.foo = 2
local.foo.should == 2
2014-01-21 10:32:03 -05:00
end
2014-01-30 20:39:23 -05:00
it "duplicates a copy on read from the parent" do
ukraine = "i love"
2014-01-30 20:43:13 -05:00
local = Pry::Config.new Pry::Config.from_hash(home: ukraine)
local.home.equal?(ukraine).should == false
2014-01-21 10:32:03 -05:00
end
it "traverses through a chain of parents" do
root = Pry::Config.from_hash({foo: 21})
local1 = Pry::Config.new(root)
local2 = Pry::Config.new(local1)
local3 = Pry::Config.new(local2)
local3.foo.should == 21
end
2014-01-21 10:32:03 -05:00
end
2014-01-31 08:18:32 -05:00
describe "#forget" do
it "forgets a local key" do
local = Pry::Config.new Pry::Config.from_hash(foo: 1)
local.foo = 2
local.foo.should == 2
local.forget(:foo)
local.foo.should == 1
end
end
describe "#to_hash" do
it "provides a copy of local key & value pairs as a Hash" do
local = Pry::Config.new Pry::Config.from_hash(bar: true)
local.foo = "21"
local.to_hash.should == { "foo" => "21" }
end
end
describe "#merge!" do
it "can merge a Hash-like object" do
local = Pry::Config.new
local.merge! Pry::Config.from_hash(foo: 21)
local.foo.should == 21
end
it "can merge a Hash" do
local = Pry::Config.new
local.merge!(foo: 21)
local.foo.should == 21
end
end
2014-01-30 20:39:23 -05:00
describe "#[]=" do
it "stores keys as strings" do
local = Pry::Config.from_hash({})
local[:zoo] = "hello"
local.to_hash.should == { "zoo" => "hello" }
2014-01-21 10:32:03 -05:00
end
end
end