tango 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,12 +4,12 @@ module Tango
4
4
  module Shell
5
5
 
6
6
  def shell(command, *args)
7
- options = { :echo => true }
7
+ options = { :echo => true, :env_vars => {} }
8
8
  options.merge!(args.pop) if args.last.is_a?(Hash)
9
9
 
10
10
  log "% #{command} #{args.join(' ')}\n\n" if options[:echo]
11
11
 
12
- pid, pipe = fork_and_exec(command, *args)
12
+ pid, pipe = fork_and_exec(command, options[:env_vars], *args)
13
13
  output = collect_output(pipe, options[:echo])
14
14
  Process.waitpid(pid)
15
15
  pipe.close
@@ -32,12 +32,13 @@ module Tango
32
32
 
33
33
  private
34
34
 
35
- def fork_and_exec(command, *args)
35
+ def fork_and_exec(command, env_vars, *args)
36
36
  read_end, write_end = IO.pipe
37
37
  pid = fork do
38
38
  read_end.close
39
39
  STDOUT.reopen(write_end)
40
40
  STDERR.reopen(write_end)
41
+ env_vars.each { |key, value| ENV[key] = value }
41
42
  exec(command, *args)
42
43
  end
43
44
  write_end.close
@@ -1,3 +1,3 @@
1
1
  module Tango
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -23,7 +23,7 @@ module Tango
23
23
  result = @stub_class.new.shell("test", "a", "=", "b")
24
24
  result.status.should == 1
25
25
  result.succeeded?.should be_false
26
- result.failed?.should be_true
26
+ result.failed?.should be_true
27
27
  end
28
28
 
29
29
  it "should accept commands as a single argument" do
@@ -53,6 +53,12 @@ module Tango
53
53
  @stub.shell("echo", "Hello, world!", :echo => false).output.should == "Hello, world!\n"
54
54
  end
55
55
 
56
+ it "should export envionment variables" do
57
+ @stub = @stub_class.new
58
+
59
+ @stub.shell("env", :env_vars => {'SOMETHING' => 'some_value'}).output.should include('SOMETHING=some_value')
60
+ end
61
+
56
62
  context "shell! method" do
57
63
  it "should raise an exception if the command fails" do
58
64
  expect {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tango
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pete Yandell
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-20 00:00:00 +10:00
18
+ date: 2011-09-21 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency