wopen3 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -101,6 +101,10 @@ module Wopen3
101
101
  end
102
102
  @status = $?.exitstatus
103
103
  end
104
+
105
+ def success?
106
+ @status == 0
107
+ end
104
108
  end # class Result
105
109
 
106
110
  def self.popen3 *cmd, &block
@@ -0,0 +1,3 @@
1
+ module Wopen3
2
+ VERSION = '0.3'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+ require 'rspec'
5
+ require File.expand_path('../lib/wopen3', File.dirname(__FILE__))
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ echo 'working...'
3
+ echo 'error!' >&2
4
+ exit 64
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ echo "hello, $1!"
3
+ exit 0
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ # executable bit should not be set, so this shouldn't execute:
4
+ echo 'succeeds!'
5
+ exit 0
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ echo 'success!'
3
+ exit 0
@@ -0,0 +1,87 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Wopen3 do
4
+ describe 'system' do
5
+ context 'success' do
6
+ before do
7
+ @result = Wopen3.system('spec/tools/succeeds.sh')
8
+ end
9
+
10
+ it 'captures stdout' do
11
+ @result.stdout.should == "success!\n"
12
+ end
13
+
14
+ it 'captures stderr' do
15
+ @result.stderr.should == ''
16
+ end
17
+
18
+ it 'captures the exit status' do
19
+ @result.status.should == 0
20
+ end
21
+
22
+ it 'reports success' do
23
+ @result.should be_success
24
+ end
25
+ end
26
+
27
+ context 'failure' do
28
+ before do
29
+ @result = Wopen3.system('spec/tools/fails.sh')
30
+ end
31
+
32
+ it 'captures stdout' do
33
+ @result.stdout.should == "working...\n"
34
+ end
35
+
36
+ it 'captures stderr' do
37
+ @result.stderr.should == "error!\n"
38
+ end
39
+
40
+ it 'captures the exit status' do
41
+ @result.status.should == 64
42
+ end
43
+
44
+ it 'reports failure' do
45
+ @result.should_not be_success
46
+ end
47
+ end
48
+
49
+ context 'file not found' do
50
+ before do
51
+ @result = Wopen3.system('spec/tools/non-existent.sh')
52
+ end
53
+
54
+ it 'returns a non-zero exit status' do
55
+ @result.status.should_not == 0
56
+ end
57
+
58
+ it 'includes Errno::ENOENT in stderr' do
59
+ @result.stderr.should match(/Errno::ENOENT/)
60
+ end
61
+ end
62
+
63
+ context 'file not executable' do
64
+ before do
65
+ @result = Wopen3.system('spec/tools/not-executable.sh')
66
+ end
67
+
68
+ it 'returns a non-zero exit status' do
69
+ @result.status.should_not == 0
70
+ end
71
+
72
+ it 'includes Errno::EACCES in stderr' do
73
+ @result.stderr.should match(/Errno::EACCES/)
74
+ end
75
+ end
76
+
77
+ context 'with parameters' do
78
+ before do
79
+ @result = Wopen3.system('spec/tools/hello.sh', 'world')
80
+ end
81
+
82
+ it 'passes parameters to the forked process' do
83
+ @result.stdout.should == "hello, world!\n"
84
+ end
85
+ end
86
+ end
87
+ end
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- version: "0.2"
7
+ - 3
8
+ version: "0.3"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Wincent Colaiuta
@@ -13,10 +13,24 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-07-28 00:00:00 +02:00
16
+ date: 2010-07-29 00:00:00 +02:00
17
17
  default_executable:
18
- dependencies: []
19
-
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rspec
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 2
28
+ - 0
29
+ - 0
30
+ - beta
31
+ version: 2.0.0.beta
32
+ type: :development
33
+ version_requirements: *id001
20
34
  description: " Unlike Open3, Wopen3 does not throw away the exit code of the executed\n (grandchild) process. Only a child process is spawned and the exit\n status is returned in $? as normal.\n"
21
35
  email: win@wincent.com
22
36
  executables: []
@@ -26,7 +40,14 @@ extensions: []
26
40
  extra_rdoc_files: []
27
41
 
28
42
  files:
43
+ - lib/wopen3/version.rb
29
44
  - lib/wopen3.rb
45
+ - spec/spec_helper.rb
46
+ - spec/tools/fails.sh
47
+ - spec/tools/hello.sh
48
+ - spec/tools/not-executable.sh
49
+ - spec/tools/succeeds.sh
50
+ - spec/wopen3_spec.rb
30
51
  has_rdoc: false
31
52
  homepage: https://wincent.com/products/wopen3
32
53
  licenses: []