Permalink
Browse files

Treat with_exitstatus right

  • Loading branch information...
1 parent 8bec72d commit f3ba33c6f6dbbf1c44df5c506642826980ed7250 @jyurek jyurek committed May 18, 2011
Showing with 14 additions and 10 deletions.
  1. +0 −10 spec/cocaine/command_line_spec.rb
  2. +2 −0 spec/spec_helper.rb
  3. +12 −0 spec/support/with_exitstatus.rb
@@ -1,15 +1,5 @@
require 'spec_helper'
-def with_exitstatus_returning(code)
- saved_exitstatus = $?.nil? ? 0 : $?.exitstatus
- begin
- `ruby -e 'exit #{code.to_i}'`
- yield
- ensure
- `ruby -e 'exit #{saved_exitstatus.to_i}'`
- end
-end
-
describe Cocaine::CommandLine do
before do
Cocaine::CommandLine.path = nil
View
@@ -1,8 +1,10 @@
require 'rspec'
+require 'spec/support/with_exitstatus'
require 'mocha'
require 'bourne'
require 'cocaine'
RSpec.configure do |config|
config.mock_with :mocha
+ config.include WithExitstatus
end
@@ -0,0 +1,12 @@
+module WithExitstatus
+ def with_exitstatus_returning(code)
+ saved_exitstatus = $?.nil? ? 0 : $?.exitstatus
+ begin
+ `ruby -e 'exit #{code.to_i}'`
@evanphx

evanphx Jun 5, 2011

I'd suggest you just use sh -c "exit #{code.to_i}". No need to launch ruby just to have it exit.

@jyurek

jyurek Jun 5, 2011

Member

That's a very good point. Thanks.

@jyurek

jyurek Jun 6, 2011

Member

Actually, just thought of something... this wouldn't work on Windows.

+ yield
+ ensure
+ `ruby -e 'exit #{saved_exitstatus.to_i}'`
+ end
+ end
+end
+

0 comments on commit f3ba33c

Please sign in to comment.