From f732bbb1e264b6ccc4fc2c1e9b99a8b9838d2199 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Wed, 16 Oct 2013 17:52:06 -0700 Subject: Add a root config_dir config option Also, refactor path joins in Config to a method that will support components containing a trailing separator or not. --- spec/unit/config_spec.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'spec/unit/config_spec.rb') diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index 1b4241b7c8..cb48ab5bcc 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -202,6 +202,70 @@ describe Chef::Config do Chef::Config[:environment_path].should == environment_path end + + describe "joining platform specific paths" do + + context "on UNIX" do + before do + Chef::Config.stub(:on_windows?).and_return(false) + end + + it "joins components when some end with separators" do + Chef::Config.path_join("/foo/", "bar", "baz").should == "/foo/bar/baz" + end + + it "joins components that don't end in separators" do + Chef::Config.path_join("/foo", "bar", "baz").should == "/foo/bar/baz" + end + + end + + context "on Windows" do + before do + Chef::Config.stub(:on_windows?).and_return(true) + end + + it "joins components with the windows separator" do + Chef::Config.path_join('c:\\foo\\', 'bar', "baz").should == 'c:\\foo\\bar\\baz' + end + end + end + + describe "setting the config dir" do + + before do + Chef::Config.stub(:on_windows?).and_return(false) + Chef::Config.config_file = "/etc/chef/client.rb" + end + + context "by default" do + it "is the parent dir of the config file" do + Chef::Config.config_dir.should == "/etc/chef" + end + end + + context "when chef is running in local mode" do + before do + Chef::Config.local_mode = true + Chef::Config.user_home = "/home/charlie" + end + + it "is in the user's home dir" do + Chef::Config.config_dir.should == "/home/charlie/.chef/" + end + end + + context "when explicitly set" do + before do + Chef::Config.config_dir = "/other/config/dir/" + end + + it "uses the explicit value" do + Chef::Config.config_dir.should == "/other/config/dir/" + end + end + + end end describe "Chef::Config[:user_home]" do -- cgit v1.2.1