Skip to content

Commit

Permalink
Return the command's exit code from Shell#result, not a boolean like …
Browse files Browse the repository at this point in the history
…#ok?.
  • Loading branch information
benhoskings committed Jun 9, 2011
1 parent 1c05010 commit d68594a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/babushka/shell.rb
Expand Up @@ -8,11 +8,11 @@ def initialize cmd, opts
@cmd, @opts = (cmd.is_a?(Array) ? cmd : [cmd]), opts
end

def ok?; result end
def ok?; result == 0 end

def run &block
@stdout, @stderr = '', ''
@result = invoke == 0
@result = invoke
print "#{" " * (@progress.length + 1)}#{"\b" * (@progress.length + 1)}" unless @progress.nil?

if block_given?
Expand Down
19 changes: 19 additions & 0 deletions spec/babushka/shell_spec.rb
@@ -0,0 +1,19 @@
require 'spec_helper'

describe Shell, '#ok?' do
it "should return true on success" do
Shell.new('true', {}).run(&:ok?).should be_true
end
it "should return false on failure" do
Shell.new('false', {}).run(&:ok?).should be_false
end
end

describe Shell, '#result' do
it "should return zero on success" do
Shell.new('true', {}).run(&:result).should == 0
end
it "should return non-zero on failure" do
Shell.new('false', {}).run(&:result).should == 1
end
end

0 comments on commit d68594a

Please sign in to comment.