scmd 2.1.2 → 2.2.0
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.
- data/Gemfile +6 -2
- data/lib/scmd/command.rb +12 -5
- data/lib/scmd/version.rb +1 -1
- data/test/unit/command_tests.rb +29 -1
- metadata +11 -11
data/Gemfile
CHANGED
data/lib/scmd/command.rb
CHANGED
@@ -14,11 +14,12 @@ module Scmd
|
|
14
14
|
READ_CHECK_TIMEOUT = 0.001 # seconds
|
15
15
|
DEFAULT_STOP_TIMEOUT = 3 # seconds
|
16
16
|
|
17
|
-
attr_reader :cmd_str
|
17
|
+
attr_reader :cmd_str, :env
|
18
18
|
attr_reader :pid, :exitstatus, :stdout, :stderr
|
19
19
|
|
20
|
-
def initialize(cmd_str)
|
20
|
+
def initialize(cmd_str, env = nil)
|
21
21
|
@cmd_str = cmd_str
|
22
|
+
@env = stringify_hash(env || {})
|
22
23
|
reset_attrs
|
23
24
|
end
|
24
25
|
|
@@ -130,7 +131,7 @@ module Scmd
|
|
130
131
|
reset_attrs
|
131
132
|
@stop_r, @stop_w = IO.pipe
|
132
133
|
@read_output_thread = nil
|
133
|
-
@child_process = ChildProcess.new(@cmd_str)
|
134
|
+
@child_process = ChildProcess.new(@cmd_str, @env)
|
134
135
|
end
|
135
136
|
|
136
137
|
def teardown_run
|
@@ -154,12 +155,18 @@ module Scmd
|
|
154
155
|
::Process.kill sig, @child_process.pid
|
155
156
|
end
|
156
157
|
|
158
|
+
def stringify_hash(hash)
|
159
|
+
hash.inject({}) do |h, (k, v)|
|
160
|
+
h.merge(k.to_s => v.to_s)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
157
164
|
class ChildProcess
|
158
165
|
|
159
166
|
attr_reader :pid, :stdin, :stdout, :stderr
|
160
167
|
|
161
|
-
def initialize(cmd_str)
|
162
|
-
@pid, @stdin, @stdout, @stderr = *::POSIX::Spawn::popen4(cmd_str)
|
168
|
+
def initialize(cmd_str, env)
|
169
|
+
@pid, @stdin, @stdout, @stderr = *::POSIX::Spawn::popen4(env, cmd_str)
|
163
170
|
@wait_pid, @wait_status = nil, nil
|
164
171
|
end
|
165
172
|
|
data/lib/scmd/version.rb
CHANGED
data/test/unit/command_tests.rb
CHANGED
@@ -11,7 +11,8 @@ class Scmd::Command
|
|
11
11
|
end
|
12
12
|
subject { @success_cmd }
|
13
13
|
|
14
|
-
should have_readers :cmd_str, :
|
14
|
+
should have_readers :cmd_str, :env
|
15
|
+
should have_readers :pid, :exitstatus, :stdout, :stderr
|
15
16
|
should have_imeths :run, :run!
|
16
17
|
should have_imeths :start, :wait, :stop, :kill
|
17
18
|
should have_imeths :running?, :success?
|
@@ -21,6 +22,18 @@ class Scmd::Command
|
|
21
22
|
assert_equal "echo hi", subject.to_s
|
22
23
|
end
|
23
24
|
|
25
|
+
should "default its env to an empty hash" do
|
26
|
+
assert_equal({}, subject.env)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "stringify its env hash" do
|
30
|
+
cmd = Scmd::Command.new("echo $SCMD_TEST_VAR", {
|
31
|
+
:SCMD_TEST_VAR => 1
|
32
|
+
})
|
33
|
+
expected = { 'SCMD_TEST_VAR' => '1' }
|
34
|
+
assert_equal expected, cmd.env
|
35
|
+
end
|
36
|
+
|
24
37
|
should "default its result values" do
|
25
38
|
assert_nil subject.pid
|
26
39
|
assert_nil subject.exitstatus
|
@@ -190,4 +203,19 @@ class Scmd::Command
|
|
190
203
|
|
191
204
|
end
|
192
205
|
|
206
|
+
class WithEnvVarTests < UnitTests
|
207
|
+
desc "with environment variables"
|
208
|
+
setup do
|
209
|
+
@cmd = Scmd::Command.new("echo $SCMD_TEST_VAR", {
|
210
|
+
'SCMD_TEST_VAR' => 'test'
|
211
|
+
})
|
212
|
+
end
|
213
|
+
|
214
|
+
should "use them when running the command" do
|
215
|
+
@cmd.run
|
216
|
+
assert_equal "test\n", @cmd.stdout
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
193
221
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 2.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,11 +16,9 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2014-06-13 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: assert
|
23
|
-
prerelease: false
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
@@ -31,11 +29,11 @@ dependencies:
|
|
31
29
|
- 2
|
32
30
|
- 3
|
33
31
|
version: "2.3"
|
34
|
-
type: :development
|
35
32
|
version_requirements: *id001
|
36
|
-
|
37
|
-
name:
|
33
|
+
type: :development
|
34
|
+
name: assert
|
38
35
|
prerelease: false
|
36
|
+
- !ruby/object:Gem::Dependency
|
39
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
38
|
none: false
|
41
39
|
requirements:
|
@@ -45,8 +43,10 @@ dependencies:
|
|
45
43
|
segments:
|
46
44
|
- 0
|
47
45
|
version: "0"
|
48
|
-
type: :runtime
|
49
46
|
version_requirements: *id002
|
47
|
+
type: :runtime
|
48
|
+
name: posix-spawn
|
49
|
+
prerelease: false
|
50
50
|
description: Build and run system commands.
|
51
51
|
email:
|
52
52
|
- kelly@kellyredding.com
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements: []
|
107
107
|
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.8.
|
109
|
+
rubygems_version: 1.8.29
|
110
110
|
signing_key:
|
111
111
|
specification_version: 3
|
112
112
|
summary: Build and run system commands.
|