guard-rack 2.1.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1693fd9ffffc04e573e62d07bb451f41c683f208
4
- data.tar.gz: ae10b900e9a66affab8ca576d0b812088580c61e
3
+ metadata.gz: 1027a4c30df921126d63d31e33a24640bb0324f2
4
+ data.tar.gz: d41f10eab3a4f8e824963a2554438887112d4827
5
5
  SHA512:
6
- metadata.gz: bf801856afb6a1c92995030f9e8c059fba2dccda7de9d3bacde809691cebc878fb00998c6fa5e0247a5088d0f260517118a14c7592561938235ebc802b86b88a
7
- data.tar.gz: 75cf912170aa128c42e014711e17d7471db233d04ccd99f024dca57220047e1e6576204872bddc56038d25ee0cb9fa85431b724057f4d28470aabd82e5841ff2
6
+ metadata.gz: 17708fee8472eb67659aea02a64821f3a4b125b81539e147518bd9aaabf524fdcc04ea419df9c8cce122a5aafc481861229072297ee3437d584db5450f630232
7
+ data.tar.gz: d23e966a7226cc183d3040cc23492b09be2ccc4beeaca75ca2e40c88c1be313f41611c55ea518748b5be4d98f4f709c884ee8562d0bbcd7d1720cfa098236c1b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 2.2.0 (4/16/2016)
2
+ =================
3
+
4
+ * [#23](https://github.com/dblock/guard-rack/pull/23) Added Windows support - [@jonyeezs](https://github.com/jonyeezs).
5
+
1
6
  2.1.1 (03/07/2015)
2
7
  ============
3
8
 
@@ -55,4 +60,3 @@
55
60
  ================
56
61
 
57
62
  * Initial public release - [@dblock](https://github.com/dblock).
58
-
data/lib/guard/rack.rb CHANGED
@@ -8,15 +8,15 @@ module Guard
8
8
  attr_reader :options, :runner
9
9
 
10
10
  DEFAULT_OPTIONS = {
11
- port: 9292,
12
- host: '0.0.0.0',
13
- environment: 'development',
11
+ port: 9292,
12
+ host: '0.0.0.0',
13
+ environment: 'development',
14
14
  start_on_start: true,
15
- force_run: false,
16
- timeout: 20,
17
- debugger: false,
18
- config: 'config.ru',
19
- cmd: 'rackup'
15
+ force_run: false,
16
+ timeout: 20,
17
+ debugger: false,
18
+ config: 'config.ru',
19
+ cmd: 'rackup'
20
20
  }
21
21
 
22
22
  def initialize(options = {})
@@ -0,0 +1,59 @@
1
+ require 'timeout'
2
+
3
+ module Guard
4
+ class Rack
5
+ class CustomProcess
6
+ attr_reader :options
7
+
8
+ def self.new(options = {})
9
+ if Gem.win_platform?
10
+ os_instance = Windows.allocate
11
+ else
12
+ os_instance = Nix.allocate
13
+ end
14
+ os_instance.send :initialize, options
15
+ os_instance
16
+ end
17
+
18
+ def initialize(options)
19
+ @options = options
20
+ end
21
+
22
+ class Nix < Rack::CustomProcess
23
+ def kill(pid, force = false)
24
+ result = -1
25
+ UI.debug("Trying to kill Rack (PID #{pid})...")
26
+ unless force
27
+ Process.kill('INT', pid)
28
+ begin
29
+ Timeout.timeout(options[:timeout]) do
30
+ _, status = Process.wait2(pid)
31
+ result = status.exitstatus
32
+ UI.debug("Killed Rack (Exit status: #{result})")
33
+ end
34
+ rescue Timeout::Error
35
+ UI.debug("Couldn't kill Rack with INT, switching to TERM")
36
+ force = true
37
+ end
38
+ end
39
+ Process.kill('TERM', pid) if force
40
+ result
41
+ end
42
+ end
43
+
44
+ class Windows < Rack::CustomProcess
45
+ def kill(pid, _force = true)
46
+ # Doesn't matter if its forceful or not. There's only one way of ending it
47
+ system("taskkill /pid #{pid} /T /f")
48
+ result = $CHILD_STATUS.exitstatus
49
+ if result == 0
50
+ UI.debug("Killed Rack (Exit status: #{result})")
51
+ else
52
+ UI.debug("Couldn't kill Rack")
53
+ end
54
+ result
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
- require 'timeout'
3
2
  require 'spoon'
4
3
  require 'guard/rack/command'
4
+ require 'guard/rack/custom_process'
5
5
 
6
6
  module Guard
7
7
  class RackRunner
@@ -38,26 +38,7 @@ module Guard
38
38
  private
39
39
 
40
40
  def kill(pid, force = false)
41
- result = -1
42
-
43
- UI.debug("Trying to kill Rack (PID #{pid})...")
44
- unless force
45
- Process.kill('INT', pid)
46
- begin
47
- Timeout.timeout(options[:timeout]) do
48
- _, status = Process.wait2(pid)
49
- result = status.exitstatus
50
- UI.debug("Killed Rack (Exit status: #{result})")
51
- end
52
- rescue Timeout::Error
53
- UI.debug("Couldn't kill Rack with INT, switching to TERM")
54
- force = true
55
- end
56
- end
57
-
58
- Process.kill('TERM', pid) if force
59
-
60
- result
41
+ Guard::Rack::CustomProcess.new(options).kill pid, force
61
42
  end
62
43
 
63
44
  def run_rack_command!
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module RackVersion
3
- VERSION = '2.1.1'
3
+ VERSION = '2.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+ require 'guard/rack/custom_process'
3
+
4
+ describe Guard::Rack::CustomProcess do
5
+ let(:options) { { environment: 'development', port: 'one', config: 'config.ru', host: '0.0.0.0', timeout: 1 } }
6
+ let(:process) { Guard::Rack::CustomProcess }
7
+
8
+ describe 'create instance' do
9
+ context '*nix' do
10
+ before do
11
+ Gem.stubs(:win_platform?).returns(false)
12
+ end
13
+
14
+ it 'should instantiate correctly' do
15
+ instance = process.new(options)
16
+ expect(instance).to be_a Guard::Rack::CustomProcess::Nix
17
+ end
18
+ end
19
+
20
+ context 'windows' do
21
+ before do
22
+ Gem.stubs(:win_platform?).returns(true)
23
+ end
24
+
25
+ it 'should instantiate correctly' do
26
+ instance = process.new(options)
27
+ expect(instance).to be_a Guard::Rack::CustomProcess::Windows
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '*nix' do
33
+ before do
34
+ Gem.stubs(:win_platform?).returns(false)
35
+ end
36
+
37
+ context 'pid exists' do
38
+ let(:pid) { 12_345 }
39
+ let(:status_stub) { stub('process exit status') }
40
+ let(:subject) { process.new(options) }
41
+ let(:wait_stub) { Process.stubs(:wait2) }
42
+
43
+ before do
44
+ Process.expects(:kill).with('INT', pid)
45
+ end
46
+
47
+ context 'rackup returns successful exit status' do
48
+ before do
49
+ wait_stub.returns([pid, status_stub])
50
+ status_stub.stubs(:exitstatus).returns(0)
51
+ end
52
+
53
+ it 'should return true' do
54
+ expect(subject.kill pid).to eq(0)
55
+ end
56
+ end
57
+
58
+ context 'rackup returns unsuccessful exit status' do
59
+ before do
60
+ Guard::UI.stubs(:info)
61
+ wait_stub.returns([pid, status_stub])
62
+ status_stub.stubs(:exitstatus).returns(1)
63
+ end
64
+
65
+ it 'should return false' do
66
+ expect(subject.kill pid).to eq(1)
67
+ end
68
+ end
69
+
70
+ context 'kill times out' do
71
+ before do
72
+ wait_stub.raises(Timeout::Error)
73
+ Process.expects(:kill).with('TERM', pid)
74
+ end
75
+
76
+ it 'should return false' do
77
+ expect(subject.kill pid).to eq(-1)
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ describe 'windows' do
84
+ before do
85
+ Gem.stubs(:win_platform?).returns(true)
86
+ end
87
+
88
+ context 'pid exist' do
89
+ let(:pid) { 123_45 }
90
+ let(:subject) { process.new }
91
+ before do
92
+ subject.expects(:system).with("taskkill /pid #{pid} /T /f")
93
+ end
94
+
95
+ describe 'kill' do
96
+ context 'successful exit status' do
97
+ before do
98
+ $CHILD_STATUS.stubs(:exitstatus).returns 0
99
+ end
100
+
101
+ it 'should result in 0' do
102
+ expect(subject.kill pid).to eq(0)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -37,7 +37,7 @@ describe Guard::RackRunner do
37
37
  describe '#start' do
38
38
  let(:unmanaged_pid) { 4567 }
39
39
  let(:pid) { 1234 }
40
- let(:kill_expectation) { Process.expects(:kill).with('TERM', unmanaged_pid) }
40
+ let(:kill_expectation) { runner.expects(:kill) }
41
41
 
42
42
  before do
43
43
  runner.expects(:spawn).once.returns(pid)
@@ -70,21 +70,17 @@ describe Guard::RackRunner do
70
70
 
71
71
  describe '#stop' do
72
72
  context 'pid exists' do
73
- let(:pid) { 12_345 }
74
- let(:status_stub) { stub('process exit status') }
75
- let(:wait_stub) { Process.stubs(:wait2) }
73
+ let(:pid) { 123_45 }
74
+ let(:process) { Guard::Rack::CustomProcess.stubs(:new) }
76
75
 
77
76
  before do
78
77
  runner.stubs(:spawn).returns(pid)
79
78
  runner.start
80
-
81
- Process.expects(:kill).with('INT', pid)
82
79
  end
83
80
 
84
81
  context 'rackup returns successful exit status' do
85
82
  before do
86
- wait_stub.returns([pid, status_stub])
87
- status_stub.stubs(:exitstatus).returns(0)
83
+ process.returns(stub(kill: 0))
88
84
  end
89
85
 
90
86
  it 'should return true' do
@@ -95,25 +91,7 @@ describe Guard::RackRunner do
95
91
  context 'rackup returns unsuccessful exit status' do
96
92
  before do
97
93
  Guard::UI.stubs(:info)
98
- wait_stub.returns([pid, status_stub])
99
- status_stub.stubs(:exitstatus).returns(1)
100
- end
101
-
102
- it 'should return false' do
103
- expect(runner.stop).to be_falsey
104
- end
105
-
106
- it 'should send some kind of message to UI.info' do
107
- Guard::UI.expects(:info).with(regexp_matches(/.+/))
108
- runner.stop
109
- end
110
- end
111
-
112
- context 'kill times out' do
113
- before do
114
- Guard::UI.stubs(:info)
115
- wait_stub.raises(Timeout::Error)
116
- Process.expects(:kill).with('TERM', pid)
94
+ process.returns(stub(kill: 1))
117
95
  end
118
96
 
119
97
  it 'should return false' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -159,11 +159,13 @@ files:
159
159
  - lib/guard-rack.rb
160
160
  - lib/guard/rack.rb
161
161
  - lib/guard/rack/command.rb
162
+ - lib/guard/rack/custom_process.rb
162
163
  - lib/guard/rack/runner.rb
163
164
  - lib/guard/rack/templates/Guardfile
164
165
  - lib/guard/rack/version.rb
165
166
  - spec/lib/guard/integration.ru
166
167
  - spec/lib/guard/integration_spec.rb
168
+ - spec/lib/guard/process_spec.rb
167
169
  - spec/lib/guard/rack/command_spec.rb
168
170
  - spec/lib/guard/rack_spec.rb
169
171
  - spec/lib/guard/runner_spec.rb
@@ -188,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
190
  version: '0'
189
191
  requirements: []
190
192
  rubyforge_project:
191
- rubygems_version: 2.4.5
193
+ rubygems_version: 2.4.8
192
194
  signing_key:
193
195
  specification_version: 4
194
196
  summary: Automatically reloads your Rack based app on file change using Guard.