summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-23 16:49:48 -0400
committerHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-23 16:49:48 -0400
commit6761ca339af8a350a4424224677e05d986fa94b2 (patch)
tree3e4cfb12a3981c4818e6496d5c28fd955c193dad /spec
parentfffd9250320566aafd3c5c14af025cc93a4e6f99 (diff)
downloadmixlib-shellout-6761ca339af8a350a4424224677e05d986fa94b2.tar.gz
[RSPEC] Refactored spec for handling locale
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/shellout/shellout_spec.rb55
1 files changed, 32 insertions, 23 deletions
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb
index 5be57b4..902fe2b 100644
--- a/spec/mixlib/shellout/shellout_spec.rb
+++ b/spec/mixlib/shellout/shellout_spec.rb
@@ -257,6 +257,7 @@ describe Mixlib::ShellOut do
let(:stdout) { executed_cmd.stdout }
let(:stderr) { executed_cmd.stderr }
let(:chomped_stdout) { stdout.chomp }
+ let(:stripped_stdout) { stdout.strip }
let(:exit_status) { executed_cmd.status.exitstatus }
let(:dir) { Dir.mktmpdir }
@@ -288,6 +289,37 @@ describe Mixlib::ShellOut do
end
end
+ context 'when handling locale' do
+ subject { stripped_stdout }
+ let(:cmd) { ECHO_LC_ALL }
+
+ it "should use the C locale by default" do
+ should eql('C')
+ end
+
+ context 'with locale' do
+ let(:locale) { 'es' }
+ let(:shell_cmd) { Mixlib::ShellOut.new(cmd, :environment => {"LC_ALL" => locale}) }
+
+ it "should use the requested locale" do
+ should eql(locale)
+ end
+ end
+
+ it "does not set any locale when the user gives LC_ALL => nil" do
+ # kinda janky
+ cmd = Mixlib::ShellOut.new(ECHO_LC_ALL, :environment => {"LC_ALL" => nil})
+ cmd.run_command
+ if !ENV['LC_ALL'] && windows?
+ expected = "%LC_ALL%"
+ else
+ expected = ENV['LC_ALL'].to_s.strip
+ end
+ cmd.stdout.strip.should == expected
+ end
+
+ end
+
context "with a live stream" do
let(:stream) { StringIO.new }
let(:shell_cmd) { Mixlib::ShellOut.new(%q{ruby -e 'puts "hello"'}, :live_stream => stream) }
@@ -632,29 +664,6 @@ describe Mixlib::ShellOut do
end
end
- it "uses the C locale by default" do
- cmd = Mixlib::ShellOut.new(ECHO_LC_ALL)
- cmd.run_command
- cmd.stdout.strip.should == 'C'
- end
-
- it "does not set any locale when the user gives LC_ALL => nil" do
- # kinda janky
- cmd = Mixlib::ShellOut.new(ECHO_LC_ALL, :environment => {"LC_ALL" => nil})
- cmd.run_command
- if !ENV['LC_ALL'] && windows?
- expected = "%LC_ALL%"
- else
- expected = ENV['LC_ALL'].to_s.strip
- end
- cmd.stdout.strip.should == expected
- end
-
- it "uses the requested locale" do
- cmd = Mixlib::ShellOut.new(ECHO_LC_ALL, :environment => {"LC_ALL" => 'es'})
- cmd.run_command
- cmd.stdout.strip.should == 'es'
- end
it "recovers the error message when exec fails" do
cmd = Mixlib::ShellOut.new("fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu")