procession 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,16 @@
1
1
  # Procession
2
2
 
3
3
  Runs a [child process](https://github.com/jarib/childprocess) and blocks until it writes something specific to stdout. Terminates the child process at exit time.
4
+
5
+ The following example blocks until __Server Started__ comes out of STDOUT as a result of executing __PORT=3455 /home/me/my\_project/bin/server__
6
+
7
+ ```ruby
8
+ require 'procession'
9
+
10
+ Procession::Process.new(
11
+ working_dir: '/home/me/my_project/bin',
12
+ command: './server',
13
+ environment: { PORT: 3455 },
14
+ await: /Server Started/
15
+ ).start
16
+ ```
@@ -7,8 +7,9 @@ module Procession
7
7
  @await = options.delete(:await)
8
8
  @working_dir = options.delete(:working_dir)
9
9
  @environment = options.delete(:environment)
10
+ @inherit_output = options.delete(:inherit_output)
10
11
  end
11
-
12
+
12
13
  def start
13
14
  args = @command.split(' ')
14
15
  @proc = ChildProcess.build(*args)
@@ -19,17 +20,17 @@ module Procession
19
20
  r, w = IO.pipe
20
21
 
21
22
  @proc.io.stdout = @proc.io.stderr = w
22
-
23
+ @proc.leader = true
23
24
  @proc.start
24
25
  w.close
25
-
26
+
26
27
  all_output = ""
27
-
28
+
28
29
  begin
29
30
  started = false
30
31
  until started
31
32
  partial = r.readpartial(8192)
32
- puts partial if ENV['CAPPIE_DEBUG']
33
+ puts partial if @inherit_output
33
34
  all_output << partial
34
35
  if (all_output =~ @await)
35
36
  started = true
@@ -38,20 +39,20 @@ module Procession
38
39
  rescue EOFError
39
40
  raise ProcessExitedError.new "The app process exited\nSTDOUT:\n#{all_output}"
40
41
  end
41
-
42
+
42
43
  Thread.new do
43
44
  while true
44
45
  partial = r.readpartial(8192)
45
- puts partial if ENV['CAPPIE_DEBUG']
46
+ puts partial if @inherit_output
46
47
  end
47
48
  end
48
-
49
+
49
50
  at_exit do
50
51
  @proc.stop
51
52
  end
52
-
53
+
53
54
  @proc.io.inherit!
54
-
55
+
55
56
  @proc
56
57
  end
57
58
 
@@ -65,6 +66,6 @@ module Procession
65
66
  @proc.cwd = @working_dir unless @working_dir.nil?
66
67
  end
67
68
  end
68
-
69
+
69
70
  class ProcessExitedError < RuntimeError; end
70
71
  end
@@ -1,3 +1,3 @@
1
1
  module Procession
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/procession.gemspec CHANGED
@@ -14,7 +14,8 @@ Gem::Specification.new do |s|
14
14
  s.platform = Gem::Platform::RUBY
15
15
 
16
16
  s.add_runtime_dependency 'childprocess', '>= 0.3.8'
17
-
17
+
18
+ s.add_development_dependency 'rspec-core', '>= 3.1.0'
18
19
  s.add_development_dependency 'rspec-expectations', '>= 2.0.1'
19
20
  s.add_development_dependency 'rack', '>= 1.5.2'
20
21
 
@@ -0,0 +1,4 @@
1
+ child_app_path = File.expand_path("../example_child_app.rb", __FILE__)
2
+
3
+ puts "Starting child app..."
4
+ spawn("ruby", child_app_path)
@@ -0,0 +1,10 @@
1
+ # creates a file called delete_me.txt after 0.5s
2
+
3
+ temp_filename = File.expand_path("../delete_me.txt", __FILE__)
4
+
5
+ sleep 0.5
6
+
7
+ File.open(temp_filename, 'w') do |f|
8
+ f.write("""This file is created by example_child_app.rb, which should
9
+ never actually happen, because the child process is killed.""")
10
+ end
@@ -3,23 +3,27 @@ require_relative '../../lib/procession/process'
3
3
  module Procession
4
4
 
5
5
  describe Process do
6
-
6
+
7
7
  def example_app_path
8
8
  File.join(File.dirname(__FILE__), "example_app.rb")
9
9
  end
10
-
10
+
11
+ def example_app_with_child_path
12
+ File.join(File.dirname(__FILE__), "example_app_with_child.rb")
13
+ end
14
+
11
15
  it 'runs a process and awaits some output' do
12
16
  process = Process.new(command: "ruby #{example_app_path}", await: /#{Dir.pwd}/).start
13
17
  process.should be_alive
14
18
  process.stop
15
19
  end
16
-
20
+
17
21
  it 'sets environment variables' do
18
22
  process = Process.new(command: "ruby #{example_app_path}", environment: { FOO: 'omg' }, await: /omg/).start
19
23
  process.should be_alive
20
24
  process.stop
21
25
  end
22
-
26
+
23
27
  it 'accepts a working directory' do
24
28
  dir = File.dirname(__FILE__)
25
29
  Dir.chdir dir do
@@ -29,14 +33,25 @@ module Procession
29
33
  end
30
34
  end
31
35
 
36
+ it 'kills the whole process tree' do
37
+ temp_path = File.join(File.dirname(__FILE__), "delete_me.txt")
38
+ File.delete(temp_path) if File.exist?(temp_path)
39
+ process = Process.new(command: "ruby #{example_app_with_child_path}",
40
+ await: /Starting child app/).start
41
+ sleep 0.2
42
+ process.stop
43
+ sleep 0.4
44
+ expect(File.exist?(temp_path)).to be_false
45
+ end
46
+
32
47
  describe 'when the process exits' do
33
48
  it 'raises an exception with the stdout output' do
34
- lambda {
49
+ expect(lambda {
35
50
  Process.new(command: 'pwd').start
36
- }.should raise_error("The app process exited\nSTDOUT:\n#{Dir.pwd}\n")
51
+ }).to raise_error("The app process exited\nSTDOUT:\n#{Dir.pwd}\n")
37
52
  end
38
53
  end
39
-
54
+
40
55
  end
41
56
 
42
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procession
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-28 00:00:00.000000000 Z
12
+ date: 2014-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.3.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec-core
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.1.0
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rspec-expectations
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +88,8 @@ files:
72
88
  - lib/procession/version.rb
73
89
  - procession.gemspec
74
90
  - spec/procession/example_app.rb
91
+ - spec/procession/example_app_with_child.rb
92
+ - spec/procession/example_child_app.rb
75
93
  - spec/procession/procession_spec.rb
76
94
  homepage: http://github.com/featurist/procession
77
95
  licenses: []
@@ -97,5 +115,6 @@ rubyforge_project:
97
115
  rubygems_version: 1.8.24
98
116
  signing_key:
99
117
  specification_version: 3
100
- summary: procession-0.0.1
118
+ summary: procession-0.0.2
101
119
  test_files: []
120
+ has_rdoc: