diff options
author | John Keiser <jkeiser@opscode.com> | 2013-10-15 20:41:52 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-10-15 20:41:52 -0700 |
commit | e1c6bef68597f5c4f418107ef9e3638e44cc8cf7 (patch) | |
tree | c6871e3dcded48265f2b82c26ab13cd62a0ba2be /spec/unit | |
parent | 2da5abd0648f3ba6977d3a69d858078237bee585 (diff) | |
download | chef-e1c6bef68597f5c4f418107ef9e3638e44cc8cf7.tar.gz |
Add --config-file-jail to avoid loading user knife.rb in tests
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/application_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/knife/config_file_selection_spec.rb | 17 |
2 files changed, 9 insertions, 13 deletions
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 9d473bbefb..e27a5cddb8 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -108,12 +108,14 @@ describe Chef::Application do end it "should configure chef::config from a file" do + Chef::Application.should_receive(:config_file_exists?).with('/etc/chef/default.rb').and_return(true) File.should_receive(:open).with("/etc/chef/default.rb").and_yield(@config_file) Chef::Config.should_receive(:from_file).with(@config_file.path) @app.configure_chef end it "should merge the local config hash into chef::config" do + Chef::Application.should_receive(:config_file_exists?).with('/etc/chef/default.rb').and_return(true) File.should_receive(:open).with("/etc/chef/default.rb").and_yield(@config_file) @app.configure_chef Chef::Config.rspec_ran.should == "true" @@ -128,7 +130,7 @@ describe Chef::Application do it "should emit a warning" do Chef::Config.should_not_receive(:from_file).with("/etc/chef/default.rb") - Chef::Log.should_receive(:warn).with("No config file found or specified on command line, not loading.") + Chef::Log.should_receive(:warn).with("No config file found or specified on command line, using command line options.") @app.configure_chef end end @@ -164,6 +166,7 @@ describe Chef::Application do after {@config_file.unlink} it "should configure chef::config from an URL" do + Chef::Application.should_receive(:config_file_exists?).with('http://example.com/foo.rb').and_call_original Chef::REST.should_receive(:new).with("", nil, nil).at_least(1).times.and_return(@rest) @rest.should_receive(:fetch).with("http://example.com/foo.rb").and_yield(@config_file) @app.configure_chef diff --git a/spec/unit/knife/config_file_selection_spec.rb b/spec/unit/knife/config_file_selection_spec.rb index 33aaddbf48..0aa77392f3 100644 --- a/spec/unit/knife/config_file_selection_spec.rb +++ b/spec/unit/knife/config_file_selection_spec.rb @@ -38,6 +38,7 @@ describe Chef::Knife do env_config = File.expand_path(File.join(Dir.tmpdir, 'knife.rb')) File.stub!(:exist?).and_return(false) File.stub!(:exist?).with(env_config).and_return(true) + Chef::Application.stub(:config_file_exists?) { |arg| arg == env_config } ENV['KNIFE_HOME'] = Dir.tmpdir @knife = Chef::Knife.new @@ -47,9 +48,7 @@ describe Chef::Knife do it "configure knife from PWD" do pwd_config = "#{Dir.pwd}/knife.rb" - File.stub!(:exist?).and_return do | arg | - [ pwd_config ].include? arg - end + Chef::Application.stub(:config_file_exists?) { |arg| arg == pwd_config } @knife = Chef::Knife.new @knife.configure_chef @@ -59,9 +58,7 @@ describe Chef::Knife do it "configure knife from UPWARD" do upward_dir = File.expand_path "#{Dir.pwd}/.chef" upward_config = File.expand_path "#{upward_dir}/knife.rb" - File.stub!(:exist?).and_return do | arg | - [ upward_config ].include? arg - end + Chef::Application.stub(:config_file_exists?) { |arg| arg == upward_config } Chef::Knife.stub!(:chef_config_dir).and_return(upward_dir) @knife = Chef::Knife.new @@ -71,9 +68,7 @@ describe Chef::Knife do it "configure knife from HOME" do home_config = File.expand_path(File.join("#{ENV['HOME']}", "/.chef/knife.rb")) - File.stub!(:exist?).and_return do | arg | - [ home_config ].include? arg - end + Chef::Application.stub(:config_file_exists?) { |arg| arg == home_config } @knife = Chef::Knife.new @knife.configure_chef @@ -95,9 +90,7 @@ describe Chef::Knife do upward_config = File.expand_path "#{upward_dir}/knife.rb" home_config = File.expand_path(File.join("#{ENV['HOME']}", "/.chef/knife.rb")) configs = [ env_config, pwd_config, upward_config, home_config ] - File.stub!(:exist?).and_return do | arg | - configs.include? arg - end + Chef::Application.stub(:config_file_exists?) { |arg| configs.include?(arg) } Chef::Knife.stub!(:chef_config_dir).and_return(upward_dir) ENV['KNIFE_HOME'] = Dir.tmpdir |