summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/shellout_spec.rb65
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/support/platform_helpers.rb5
3 files changed, 39 insertions, 32 deletions
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb
index d935315..cb0a33d 100644
--- a/spec/mixlib/shellout_spec.rb
+++ b/spec/mixlib/shellout_spec.rb
@@ -42,8 +42,8 @@ describe Mixlib::ShellOut do
its(:live_stream) { should be_nil }
its(:input) { should be_nil }
- it "should set default environmental variables" do
- shell_cmd.environment.should == {"LC_ALL" => "C"}
+ it "should not set any default environmental variables" do
+ shell_cmd.environment.should == {}
end
end
@@ -314,7 +314,7 @@ describe Mixlib::ShellOut do
end
it "should add environment settings to the default" do
- shell_cmd.environment.should eql({'LC_ALL' => 'C', 'RUBY_OPTS' => '-w'})
+ shell_cmd.environment.should eql({'RUBY_OPTS' => '-w'})
end
context 'when setting custom environments' do
@@ -322,7 +322,7 @@ describe Mixlib::ShellOut do
let(:options) { { :env => environment } }
it "should also set the enviroment" do
- shell_cmd.environment.should eql({'LC_ALL' => 'C', 'RUBY_OPTS' => '-w'})
+ shell_cmd.environment.should eql({'RUBY_OPTS' => '-w'})
end
end
@@ -425,14 +425,22 @@ describe Mixlib::ShellOut do
end
context 'when handling locale' do
+ before do
+ @original_lc_all = ENV['LC_ALL']
+ ENV['LC_ALL'] = "en_US.UTF-8"
+ end
+ after do
+ ENV['LC_ALL'] = @original_lc_all
+ end
+
subject { stripped_stdout }
let(:cmd) { ECHO_LC_ALL }
let(:options) { { :environment => { 'LC_ALL' => locale } } }
context 'without specifying environment' do
let(:options) { nil }
- it "should use the C locale by default" do
- should eql('C')
+ it "should no longer use the C locale by default" do
+ should eql("en_US.UTF-8")
end
end
@@ -447,20 +455,11 @@ describe Mixlib::ShellOut do
context 'with LC_ALL set to nil' do
let(:locale) { nil }
- before do
- @original_lc_all = ENV['LC_ALL']
- ENV['LC_ALL'] = "en_US.UTF-8"
- end
-
- after do
- ENV['LC_ALL'] = @original_lc_all
- end
-
context 'when running under Unix', :unix_only do
let(:parent_locale) { ENV['LC_ALL'].to_s.strip }
- it "should use the parent process's locale" do
- should eql(parent_locale)
+ it "should unset the parent process's locale" do
+ should eql("")
end
end
@@ -574,7 +573,6 @@ describe Mixlib::ShellOut do
subject { chomped_stdout }
let(:cmd) { script_name }
-
context 'when running under Unix', :unix_only do
let(:script_content) { 'echo blah' }
@@ -620,7 +618,6 @@ describe Mixlib::ShellOut do
end
end
-
context 'with lots of long arguments' do
subject { chomped_stdout }
@@ -645,7 +642,6 @@ describe Mixlib::ShellOut do
end
end
-
context 'with backslashes' do
subject { stdout }
let(:backslashes) { %q{\\"\\\\} }
@@ -919,7 +915,6 @@ describe Mixlib::ShellOut do
end
end
-
context 'with open files for parent process' do
before do
@test_file = Tempfile.new('fd_test')
@@ -1056,7 +1051,6 @@ describe Mixlib::ShellOut do
CODE
end
-
it "should TERM the wayward child and grandchild, then KILL whoever is left" do
# note: let blocks don't correctly memoize if an exception is raised,
# so can't use executed_cmd
@@ -1321,19 +1315,26 @@ describe Mixlib::ShellOut do
end
end
end
+ end
- describe "#clean_parent_file_descriptors", :unix_only do
- # test for for_fd returning a valid File object, but close
- # throwing EBADF.
- it "should not throw an exception if fd.close throws EBADF" do
- fd = double('File')
- fd.stub(:close).at_least(:once).and_raise(Errno::EBADF)
- File.should_receive(:for_fd).at_least(:once).and_return(fd)
- shellout = Mixlib::ShellOut.new()
- shellout.instance_variable_set(:@process_status_pipe, [ 98, 99 ])
- lambda { shellout.send(:clean_parent_file_descriptors) }.should_not raise_error
+ context "when running under *nix", :requires_root, :unix_only do
+ let(:cmd) { 'whoami' }
+ let(:running_user) { shell_cmd.run_command.stdout.chomp }
+
+ context "when no user is set" do
+ it "should run as current user" do
+ running_user.should eql(ENV["USER"])
end
end
+ context "when user is specified" do
+ let(:user) { 'nobody' }
+
+ let(:options) { { :user => user } }
+
+ it "should run as specified user" do
+ running_user.should eql("#{user}")
+ end
+ end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9d51c5e..b435176 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -19,6 +19,7 @@ RSpec.configure do |config|
# Add jruby filters here
config.filter_run_excluding :windows_only => true unless windows?
config.filter_run_excluding :unix_only => true unless unix?
+ config.filter_run_excluding :requires_root => true unless root?
config.run_all_when_everything_filtered = true
config.treat_symbols_as_metadata_keys_with_true_values = true
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index 69bdbf7..c730b4d 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -24,3 +24,8 @@ else
LINE_ENDING = "\n"
ECHO_LC_ALL = "echo $LC_ALL"
end
+
+def root?
+ return false if windows?
+ Process.euid == 0
+end