guard-spork 0.1.6 → 0.1.7

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/README.rdoc CHANGED
@@ -1,13 +1,13 @@
1
1
  = Guard::Spork
2
2
 
3
- Spork guard allows to automatically & intelligently start/reload your RSpec/Cucumber Spork server(s).
3
+ Guard::Spork allows to automatically & intelligently start/reload your RSpec/Cucumber {Spork}[https://github.com/timcharper/spork] server(s).
4
4
 
5
- - Compatible with Spork 0.8.4 & 0.9.0.rc3
5
+ - Compatible with Spork 0.8.4 & 0.9.0.rc3.
6
6
  - Tested on Ruby 1.8.6, 1.8.7 & 1.9.2.
7
7
 
8
8
  == Install
9
9
 
10
- Please be sure to have {Guard}[http://github.com/guard/guard] installed before continue.
10
+ Please be sure to have {Guard}[https://github.com/guard/guard] installed before continue.
11
11
 
12
12
  Install the gem:
13
13
 
@@ -23,14 +23,13 @@ Add guard definition to your Guardfile with:
23
23
 
24
24
  == Usage
25
25
 
26
- Please read {Guard usage doc}[http://github.com/guard/guard#readme]
26
+ Please read {Guard usage doc}[https://github.com/guard/guard#readme].
27
27
 
28
28
  == Guardfile
29
29
 
30
- Spork guard can be really be adapated to all kind of projects.
31
- Please read {Guard doc}[http://github.com/guard/guard#readme] for more info about Guardfile DSL.
30
+ Please read {Guard doc}[https://github.com/guard/guard#readme] for more info about the Guardfile DSL.
32
31
 
33
- !!! IMPORTANT: place Spork guard before rspec/cucumber guards !!!
32
+ <b>IMPORTANT: place Spork guard before RSpec/Cucumber guards!</b>
34
33
 
35
34
  === Rails app
36
35
 
@@ -44,19 +43,19 @@ Please read {Guard doc}[http://github.com/guard/guard#readme] for more info abou
44
43
 
45
44
  === Running specs over Spork
46
45
 
47
- Pass the :drb => true option to {guard-rspec}[http://github.com/guard/guard-rspec] and/or {guard-cucumber}[http://github.com/guard/guard-cucumber] to run them over the Spork DRb server:
46
+ Pass the <tt>:cli => "--drb"</tt> option to {Guard::RSpec}[https://github.com/guard/guard-rspec] and/or {Guard::Cucumber}[https://github.com/guard/guard-cucumber] to run them over the Spork DRb server:
48
47
 
49
- guard 'rspec', :drb => true do
48
+ guard 'rspec', :cli => "--drb" do
50
49
  ...
51
50
  end
52
51
 
53
- guard 'cucumber', :drb => true do
52
+ guard 'cucumber', :cli => "--drb" do
54
53
  ...
55
54
  end
56
55
 
57
56
  == Options
58
57
 
59
- Spork guard automatically detect RSpec/Cucumber/Bundler presence but you can disable any of them with the corresponding options:
58
+ Guard::Spork automatically detect RSpec/Cucumber/Bundler presence but you can disable any of them with the corresponding options:
60
59
 
61
60
  guard 'spork', :cucumber => false, :bundler => false do
62
61
  ...
@@ -64,29 +63,29 @@ Spork guard automatically detect RSpec/Cucumber/Bundler presence but you can dis
64
63
 
65
64
  Available options:
66
65
 
67
- :wait => 30 # Seconds to wait server launch, default 20
66
+ :wait => 30 # Seconds to wait for the server to starts, default: 20
68
67
  :cucumber => false
69
68
  :rspec => false
70
- :bundler => false # don't use "bundle exec"
71
- :rspec_port => xxxx # default 8989
72
- :cucumber_port => xxxx # default 8990
69
+ :bundler => false # Don't use "bundle exec"
70
+ :rspec_port => 1234 # Default: 8989
71
+ :cucumber_port => 4321 # Default: 8990
73
72
 
74
73
  == Common troubleshooting
75
74
 
76
- If you can start Spork manually but get the following error message when using Spork guard:
75
+ If you can start Spork manually but get the following error message when using Guard::Spork:
77
76
 
78
- Starting Spork for RSpec ERROR: Could not start Spork for RSpec. Make sure you can use it manually first.
77
+ Starting Spork for RSpec ERROR: Could not start Spork for RSpec/Cucumber. Make sure you can use it manually first.
79
78
 
80
- Try to increase the value of the :wait option before any further investigation.
79
+ Try to increase the value of the <tt>:wait</tt> option before any further investigation.
81
80
 
82
81
  == Development
83
82
 
84
- - Source hosted at {GitHub}[http://github.com/guard/guard-spork]
85
- - Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/guard/guard-spork/issues]
83
+ - Source hosted at {GitHub}[https://github.com/guard/guard-spork]
84
+ - Report issues/Questions/Feature requests on {GitHub Issues}[https://github.com/guard/guard-spork/issues]
86
85
 
87
86
  Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
88
87
  you make.
89
88
 
90
89
  == Authors
91
90
 
92
- {Thibaud Guillaume-Gentil}[http://github.com/thibaudgg]
91
+ {Thibaud Guillaume-Gentil}[https://github.com/thibaudgg]
@@ -1,5 +1,4 @@
1
1
  require 'socket'
2
- require 'sfl'
3
2
 
4
3
  module Guard
5
4
  class Spork
@@ -11,20 +10,66 @@ module Guard
11
10
  options[:rspec_port] ||= 8989
12
11
  options[:cucumber_port] ||= 8990
13
12
  @options = options
13
+ @children = {}
14
+
15
+ Signal.trap('CHLD', self.method(:reap_children))
14
16
  end
15
17
 
16
18
  def launch_sporks(action)
17
19
  UI.info "#{action.capitalize}ing Spork for #{sporked_gems} ", :reset => true
18
- spawn(spork_command("rspec")) if rspec?
19
- spawn(spork_command("cucumber")) if cucumber?
20
+ spawn_child(spork_command("rspec")) if rspec?
21
+ spawn_child(spork_command("cucumber")) if cucumber?
20
22
  verify_launches(action)
21
23
  end
22
24
 
23
25
  def kill_sporks
26
+ UI.debug "Killing sporks #{spork_pids.join(', ')}"
24
27
  spork_pids.each { |pid| Process.kill("KILL", pid) }
25
28
  end
26
29
 
27
30
  private
31
+ def spawn_child(cmd)
32
+ pid = fork
33
+ raise "Fork failed." if pid == -1
34
+
35
+ unless pid
36
+ ignore_control_signals
37
+ exec(cmd)
38
+ end
39
+
40
+ UI.debug "Spawned spork #{pid} ('#{cmd}')"
41
+ @children[pid] = cmd
42
+ pid
43
+ end
44
+
45
+ def ignore_control_signals
46
+ Signal.trap('QUIT', 'IGNORE')
47
+ Signal.trap('INT', 'IGNORE')
48
+ Signal.trap('TSTP', 'IGNORE')
49
+ end
50
+
51
+ def reap_children(sig)
52
+ terminated_children.each do |stat|
53
+ pid = stat.pid
54
+ if cmd = @children.delete(pid)
55
+ UI.debug "Reaping spork #{pid}"
56
+ end
57
+ end
58
+ end
59
+
60
+ def terminated_children
61
+ stats = []
62
+ loop do
63
+ begin
64
+ pid, stat = Process.wait2(-1, Process::WNOHANG)
65
+ break if pid.nil?
66
+ stats << stat
67
+ rescue Errno::ECHILD
68
+ break
69
+ end
70
+ end
71
+ stats
72
+ end
28
73
 
29
74
  def spork_command(type)
30
75
  cmd_parts = []
@@ -61,7 +106,7 @@ module Guard
61
106
  end
62
107
 
63
108
  def spork_pids
64
- `ps aux | awk '/spork/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i }
109
+ @children.keys
65
110
  end
66
111
 
67
112
  def sporked_gems
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module SporkVersion
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-spork
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
4
+ hash: 21
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thibaud Guillaume-Gentil
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-21 00:00:00 +01:00
18
+ date: 2011-04-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,69 +50,54 @@ dependencies:
50
50
  version: 0.8.4
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: sfl
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - "="
60
- - !ruby/object:Gem::Version
61
- hash: 11
62
- segments:
63
- - 1
64
- - 2
65
- version: "1.2"
66
- type: :runtime
67
- version_requirements: *id003
68
53
  - !ruby/object:Gem::Dependency
69
54
  name: bundler
70
55
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ requirement: &id003 !ruby/object:Gem::Requirement
72
57
  none: false
73
58
  requirements:
74
59
  - - ~>
75
60
  - !ruby/object:Gem::Version
76
- hash: 25
61
+ hash: 15
77
62
  segments:
78
63
  - 1
79
64
  - 0
80
- - 7
81
- version: 1.0.7
65
+ - 12
66
+ version: 1.0.12
82
67
  type: :development
83
- version_requirements: *id004
68
+ version_requirements: *id003
84
69
  - !ruby/object:Gem::Dependency
85
70
  name: rspec
86
71
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ requirement: &id004 !ruby/object:Gem::Requirement
88
73
  none: false
89
74
  requirements:
90
75
  - - ~>
91
76
  - !ruby/object:Gem::Version
92
- hash: 7
77
+ hash: 27
93
78
  segments:
94
79
  - 2
95
- - 2
80
+ - 5
96
81
  - 0
97
- version: 2.2.0
82
+ version: 2.5.0
98
83
  type: :development
99
- version_requirements: *id005
84
+ version_requirements: *id004
100
85
  - !ruby/object:Gem::Dependency
101
86
  name: guard-rspec
102
87
  prerelease: false
103
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ requirement: &id005 !ruby/object:Gem::Requirement
104
89
  none: false
105
90
  requirements:
106
91
  - - ~>
107
92
  - !ruby/object:Gem::Version
108
- hash: 9
93
+ hash: 23
109
94
  segments:
110
95
  - 0
111
- - 1
112
- - 9
113
- version: 0.1.9
96
+ - 2
97
+ - 0
98
+ version: 0.2.0
114
99
  type: :development
115
- version_requirements: *id006
100
+ version_requirements: *id005
116
101
  description: Guard::Spork automatically manage Spork DRb servers
117
102
  email:
118
103
  - thibaud@thibaud.me
@@ -161,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
146
  requirements: []
162
147
 
163
148
  rubyforge_project: guard-spork
164
- rubygems_version: 1.5.0
149
+ rubygems_version: 1.3.7
165
150
  signing_key:
166
151
  specification_version: 3
167
152
  summary: Guard gem for Spork