terrapin 0.6.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +0,0 @@
1
- # coding: UTF-8
2
-
3
- module Terrapin
4
- class CommandLine
5
- class PosixRunner
6
- def self.available?
7
- return @available unless @available.nil?
8
-
9
- @available = posix_spawn_gem_available?
10
- end
11
-
12
- def self.supported?
13
- available? && !OS.java?
14
- end
15
-
16
- def supported?
17
- self.class.supported?
18
- end
19
-
20
- def call(command, env = {}, options = {})
21
- pipe = MultiPipe.new
22
- pid = spawn(env, command, options.merge(pipe.pipe_options))
23
- pipe.read_and_then do
24
- waitpid(pid)
25
- end
26
- pipe.output
27
- end
28
-
29
- private
30
-
31
- def spawn(*args)
32
- POSIX::Spawn.spawn(*args)
33
- end
34
-
35
- def waitpid(pid)
36
- Process.waitpid(pid)
37
- end
38
-
39
- def self.posix_spawn_gem_available?
40
- require 'posix/spawn'
41
- true
42
- rescue LoadError
43
- false
44
- end
45
-
46
- private_class_method :posix_spawn_gem_available?
47
- end
48
- end
49
- end
@@ -1,7 +0,0 @@
1
- module UnsettingExitstatus
2
- def assuming_no_processes_have_been_run
3
- class << $?
4
- undef_method :exitstatus
5
- end
6
- end
7
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Terrapin::CommandLine::PosixRunner do
4
- if Terrapin::CommandLine::PosixRunner.supported?
5
- it_behaves_like 'a command that does not block'
6
-
7
- it 'runs the command given and captures the output' do
8
- output = subject.call("echo hello")
9
- expect(output).to have_output "hello\n"
10
- end
11
-
12
- it 'runs the command given and captures the error output' do
13
- output = subject.call("echo hello 1>&2")
14
- expect(output).to have_error_output "hello\n"
15
- end
16
-
17
- it 'modifies the environment and runs the command given' do
18
- output = subject.call("echo $yes", {"yes" => "no"})
19
- expect(output).to have_output "no\n"
20
- end
21
-
22
- it 'sets the exitstatus when a command completes' do
23
- subject.call("ruby -e 'exit 0'")
24
- $?.exitstatus.should == 0
25
- subject.call("ruby -e 'exit 5'")
26
- $?.exitstatus.should == 5
27
- end
28
-
29
- it "runs the command it's given and allows access to stderr afterwards" do
30
- cmd = Terrapin::CommandLine.new(
31
- "ruby",
32
- "-e '$stdout.puts %{hello}; $stderr.puts %{goodbye}'",
33
- :swallow_stderr => false
34
- )
35
- cmd.run
36
- expect(cmd.command_output).to eq "hello\n"
37
- expect(cmd.command_error_output).to eq "goodbye\n"
38
- end
39
- end
40
- end