diff options
author | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-03-23 11:09:55 -0400 |
---|---|---|
committer | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-03-23 11:09:55 -0400 |
commit | 037b74cfb5bb0a79b8bdb64eee91e90893392f01 (patch) | |
tree | a22935e6cf2c0cebed0c61ad28f7e6b29c41f0aa /spec | |
parent | 6952707c60329767a12d6775fd6c325f558a440f (diff) | |
download | mixlib-shellout-037b74cfb5bb0a79b8bdb64eee91e90893392f01.tar.gz |
[RSPEC] Refactored spec for handling valid and invalid exit codes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/shellout/shellout_spec.rb | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb index 9f9e847..9e6deca 100644 --- a/spec/mixlib/shellout/shellout_spec.rb +++ b/spec/mixlib/shellout/shellout_spec.rb @@ -439,22 +439,35 @@ describe Mixlib::ShellOut do end end - it "does not raise an error if the command returns a value in the list of valid_exit_codes" do - cmd = Mixlib::ShellOut.new('ruby -e "exit 42"', :returns => 42) - cmd.run_command - lambda {cmd.error!}.should_not raise_error - end + context 'with valid exit codes' do + let(:shell_cmd) { Mixlib::ShellOut.new(cmd, :returns => valid_exit_codes) } + let(:cmd) { ruby_eval.call("exit #{exit_code}" ) } - it "raises an error if the command does not return a value in the list of valid_exit_codes" do - cmd = Mixlib::ShellOut.new('ruby -e "exit 2"', :returns => [ 0, 1, 42 ]) - cmd.run_command - lambda {cmd.error!}.should raise_error(Mixlib::ShellOut::ShellCommandFailed) - end + context 'when exiting with valid code' do + let(:valid_exit_codes) { 42 } + let(:exit_code) { 42 } - it "raises an error if the command returns 0 and the list of valid_exit_codes does not contain 0" do - cmd = Mixlib::ShellOut.new('ruby -e "exit 0"', :returns => 42) - cmd.run_command - lambda {cmd.error!}.should raise_error(Mixlib::ShellOut::ShellCommandFailed) + it "should raise InvalidCommandResult" do + lambda { executed_cmd.error! }.should_not raise_error + end + end + + context 'when exiting with invalid code' do + let(:valid_exit_codes) { [ 0, 1, 42 ] } + let(:exit_code) { 2 } + it "should raise InvalidCommandResult" do + lambda { executed_cmd.error! }.should raise_error(Mixlib::ShellOut::ShellCommandFailed) + end + end + + context 'when exiting with invalid code 0' do + let(:valid_exit_codes) { 42 } + let(:exit_code) { 0 } + + it "should raise InvalidCommandResult" do + lambda { executed_cmd.error! }.should raise_error(Mixlib::ShellOut::ShellCommandFailed) + end + end end it "includes output with exceptions from #error!" do |