guard-puma 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba3c0c0435df8f3c4ebc9383ae9afbd92bd2f41d
4
- data.tar.gz: c89ab9b1313f04b420a8ac8be2dc6a2b685f9440
3
+ metadata.gz: '0763889538f31e4bf352571ab6ec93bf6257eb74'
4
+ data.tar.gz: 2af890d006a069d855410ec87d30bd9dade720cf
5
5
  SHA512:
6
- metadata.gz: f3bf2e82c1da9bdfc4ae1d78244455642b5a07f242f0af7f4998b121492214b5322d5094b9f21b538575d04d2599a93c813055d7a07e614e98f07bce176aa60a
7
- data.tar.gz: 073f9b90a53e4aed7fd27c282d63b50ff82f54e57fec7d6579a5446d24dd539648630d0a66f99bc16f88f47ad61f27ec6c35c9a96f431bc676b00aaa8e2ec9f9
6
+ metadata.gz: 6e2ebcb761bdc9dfe8dbddd56b7e29fa7486960e2c8790ce859f71404545c92fc23005df5df733882d17cb3a2481efc85a6f2af4df6fdbead649f40b45a82b04
7
+ data.tar.gz: 6411ac22464398ac4eba2b98308ace1398d265ce88ffe0b6c6eb35fb918d767591568814d7145dd837ea02a2694fdc72d79b6ecb14cd55e0f305a46c20d7a04b
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes
2
2
 
3
+ ## 0.5.0
4
+
5
+ * Add `:pumactl` option
6
+ * Add `:restart_timeout` option
7
+ * Don't stop Puma if it was not started by Guard
8
+ * Don't notify about start when no start
9
+ * Improve `guard-compat` using (https://github.com/guard/guard-compat#migrating-your-api-calls)
10
+ * Remove unused `pry` dependency
11
+ * Update versions of dependencies
12
+
3
13
  ## 0.4.1
4
14
 
5
15
  * Improve notifications. Via #30
data/README.md CHANGED
@@ -33,17 +33,21 @@ end
33
33
 
34
34
  * `:port` is the port number to run on (default `4000`)
35
35
  * `:environment` is the environment to use (default `development`)
36
- * `:start_on_start` will start the server when starting Guard (default `true`)
36
+ * `:start_on_start` will start the server when starting Guard and stop the server when reloading/stopping Guard (default `true`)
37
37
  * `:force_run` kills any process that's holding open the listen port before attempting to (re)start Puma (default `false`).
38
38
  * `:daemon` runs the server as a daemon, without any output to the terminal that ran `guard` (default `false`).
39
39
  * `:quiet` runs the server in quiet mode, suppressing output (default `true`).
40
40
  * `:debugger` runs the server with the debugger enabled (default `false`). Required ruby-debug gem.
41
41
  * `:timeout` waits this number of seconds when restarting the Puma server before reporting there's a problem (default `20`).
42
+ * `:restart_timeout` waits this number of seconds before the next restarting the Puma server (default `1`).
42
43
  * `:config` is the path to the Puma config file (optional)
43
44
  * `:bind` is URI to bind to (tcp:// and unix:// only) (optional)
44
45
  * `:control_token` is the token to use as authentication for the control server(optional)
45
46
  * `:control_port` is the port to use for the control server(optional)
46
47
  * `:threads` is the min:max number of threads to use. Defaults to 0:16 (optional)
48
+ * `:pumactl` manages the server via `pumactl` executable instead of `puma` (default `false`)
49
+ * Incompatible with options such as `port`, `environment`, `daemon`, `bind`, `threads`
50
+ * Use with `config` option is preferred.
47
51
  * `:notifications` is the list of notification types that will be sent. Defaults to `[:restarting, :restarted, :not_restarted, :stopped]` (optional)
48
52
 
49
53
  ## Contributing
data/guard-puma.gemspec CHANGED
@@ -16,8 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.add_dependency "guard", "~> 2.14"
17
17
  gem.add_dependency "guard-compat", "~> 1.2"
18
18
  gem.add_dependency "puma", "~> 3.6"
19
- gem.add_development_dependency "rake", "~> 10.4"
20
- gem.add_development_dependency "rspec", "~> 3.5.0"
21
- gem.add_development_dependency "guard-rspec", "~> 4.7.0"
22
- gem.add_development_dependency "pry"
19
+ gem.add_development_dependency "rake", "~> 12"
20
+ gem.add_development_dependency "rspec", "~> 3.7"
21
+ gem.add_development_dependency "guard-rspec", "~> 4.7"
23
22
  end
data/lib/guard/puma.rb CHANGED
@@ -1,9 +1,6 @@
1
- require "guard"
2
- require "guard/plugin"
3
- require "guard/puma/runner"
4
- require "rbconfig"
5
- require "guard/puma/version"
6
- require "guard/compat/plugin"
1
+ require 'guard/compat/plugin'
2
+ require_relative 'puma/runner'
3
+ require_relative 'puma/version'
7
4
 
8
5
  module Guard
9
6
  class Puma < Plugin
@@ -14,11 +11,13 @@ module Guard
14
11
  end
15
12
 
16
13
  DEFAULT_OPTIONS = {
14
+ :pumactl => false,
17
15
  :port => 4000,
18
16
  :environment => default_env,
19
17
  :start_on_start => true,
20
18
  :force_run => false,
21
19
  :timeout => 20,
20
+ :restart_timeout => 1,
22
21
  :debugger => false,
23
22
  :notifications => %i[restarting restarted not_restarted stopped]
24
23
  }
@@ -28,35 +27,54 @@ module Guard
28
27
  @options = DEFAULT_OPTIONS.merge(options)
29
28
  @options[:port] = nil if @options.key?(:config)
30
29
  @runner = ::Guard::PumaRunner.new(@options)
30
+ @last_restarted = Time.now
31
31
  end
32
32
 
33
33
  def start
34
+ return unless options[:start_on_start]
34
35
  server = options[:server] ? "#{options[:server]} and " : ""
35
- UI.info "Puma starting#{port_text} in #{server}#{options[:environment]} environment."
36
- runner.start if options[:start_on_start]
36
+ Compat::UI.info(
37
+ "Puma starting#{port_text} in #{server}#{options[:environment]} environment."
38
+ )
39
+ runner.start
37
40
  end
38
41
 
39
42
  def reload
40
- UI.info "Restarting Puma..."
43
+ return if (Time.now - @last_restarted) < options[:restart_timeout]
44
+ @last_restarted = Time.now
45
+ Compat::UI.info "Restarting Puma..."
41
46
  if options[:notifications].include?(:restarting)
42
- Notifier.notify("Puma restarting#{port_text} in #{options[:environment]} environment...", :title => "Restarting Puma...", :image => :pending)
47
+ Compat::UI.notify(
48
+ "Puma restarting#{port_text} in #{options[:environment]} environment...",
49
+ title: "Restarting Puma...", image: :pending
50
+ )
43
51
  end
44
52
  if runner.restart
45
- UI.info "Puma restarted"
53
+ Compat::UI.info "Puma restarted"
46
54
  if options[:notifications].include?(:restarted)
47
- Notifier.notify("Puma restarted#{port_text}.", :title => "Puma restarted!", :image => :success)
55
+ Compat::UI.notify(
56
+ "Puma restarted#{port_text}.",
57
+ title: "Puma restarted!", image: :success
58
+ )
48
59
  end
49
60
  else
50
- UI.info "Puma NOT restarted, check your log files."
61
+ Compat::UI.info "Puma NOT restarted, check your log files."
51
62
  if options[:notifications].include?(:not_restarted)
52
- Notifier.notify("Puma NOT restarted, check your log files.", :title => "Puma NOT restarted!", :image => :failed)
63
+ Compat::UI.notify(
64
+ "Puma NOT restarted, check your log files.",
65
+ title: "Puma NOT restarted!", image: :failed
66
+ )
53
67
  end
54
68
  end
55
69
  end
56
70
 
57
71
  def stop
72
+ return unless options[:start_on_start]
58
73
  if options[:notifications].include?(:stopped)
59
- Notifier.notify("Until next time...", :title => "Puma shutting down.", :image => :pending)
74
+ Compat::UI.notify(
75
+ "Until next time...",
76
+ title: "Puma shutting down.", image: :pending
77
+ )
60
78
  end
61
79
  runner.halt
62
80
  end
@@ -6,49 +6,48 @@ module Guard
6
6
 
7
7
  MAX_WAIT_COUNT = 20
8
8
 
9
- attr_reader :options, :control_url, :control_token, :cmd_opts
9
+ attr_reader :options, :control_url, :control_token, :cmd_opts, :pumactl
10
10
 
11
11
  def initialize(options)
12
12
  @control_token = options.delete(:control_token) { |_| ::Puma::Configuration.random_token }
13
- @control = "localhost"
14
13
  @control_port = (options.delete(:control_port) || '9293')
15
- @control_url = "#{@control}:#{@control_port}"
14
+ @control_url = "localhost:#{@control_port}"
16
15
  @quiet = options.delete(:quiet) { true }
16
+ @pumactl = options.delete(:pumactl) { false }
17
17
  @options = options
18
18
 
19
- puma_options = if options[:config]
20
- {
21
- '--config' => options[:config],
22
- '--control-token' => @control_token,
23
- '--control' => "tcp://#{@control_url}",
24
- '--environment' => options[:environment]
25
- }
19
+ puma_options = {
20
+ puma_options_key(:config) => options[:config],
21
+ puma_options_key(:control_token) => @control_token,
22
+ puma_options_key(:control_url) => "tcp://#{@control_url}"
23
+ }
24
+ if options[:config]
25
+ puma_options['--config'] = options[:config]
26
26
  else
27
- {
28
- '--port' => options[:port],
29
- '--control-token' => @control_token,
30
- '--control' => "tcp://#{@control_url}",
31
- '--environment' => options[:environment]
32
- }
33
- end
34
- [:bind, :threads].each do |opt|
35
- puma_options["--#{opt}"] = options[opt] if options[opt]
27
+ puma_options['--port'] = options[:port]
36
28
  end
29
+ %i[bind threads environment]
30
+ .select { |opt| options[opt] }
31
+ .each do |opt|
32
+ if pumactl
33
+ Compat::UI.warning(
34
+ "`#{opt}` option is not compatible with `pumactl` option"
35
+ )
36
+ else
37
+ puma_options["--#{opt}"] = options[opt]
38
+ end
39
+ end
37
40
  puma_options = puma_options.to_a.flatten
38
- puma_options << '-q' if @quiet
41
+ puma_options << '--quiet' if @quiet
39
42
  @cmd_opts = puma_options.join ' '
40
43
  end
41
44
 
42
45
  def start
43
- if in_windows_cmd?
44
- Kernel.system windows_start_cmd
45
- else
46
- Kernel.system nix_start_cmd
47
- end
46
+ Kernel.system build_command('start')
48
47
  end
49
48
 
50
49
  def halt
51
- Net::HTTP.get build_uri('halt')
50
+ run_puma_command!('halt')
52
51
  # server may not have been stopped correctly, but we are halting so who cares.
53
52
  return true
54
53
  end
@@ -68,8 +67,30 @@ module Guard
68
67
 
69
68
  private
70
69
 
70
+ PUMA_OPTIONS_KEYS_BY_PUMACTL = {
71
+ true => {
72
+ config: '--config-file',
73
+ control_url: '--control-url'
74
+ }.freeze,
75
+ false => {
76
+ config: '--config',
77
+ control_url: '--control'
78
+ }.freeze
79
+ }.freeze
80
+
81
+ private_constant :PUMA_OPTIONS_KEYS_BY_PUMACTL
82
+
83
+ def puma_options_key(key)
84
+ keys = PUMA_OPTIONS_KEYS_BY_PUMACTL[@pumactl]
85
+ keys.fetch(key) { |k| "--#{k.to_s.tr('_', '-')}" }
86
+ end
87
+
71
88
  def run_puma_command!(cmd)
72
- Net::HTTP.get build_uri(cmd)
89
+ if pumactl
90
+ Kernel.system build_command(cmd)
91
+ else
92
+ Net::HTTP.get build_uri(cmd)
93
+ end
73
94
  return true
74
95
  rescue Errno::ECONNREFUSED => e
75
96
  # server may not have been started correctly.
@@ -80,12 +101,22 @@ module Guard
80
101
  URI "http://#{control_url}/#{cmd}?token=#{control_token}"
81
102
  end
82
103
 
83
- def nix_start_cmd
84
- %{sh -c 'cd #{Dir.pwd} && puma #{cmd_opts} &'}
104
+ def build_command(cmd)
105
+ puma_cmd = "#{pumactl ? 'pumactl' : 'puma'} #{cmd_opts} #{cmd if pumactl}"
106
+ background = cmd == 'start'
107
+ if in_windows_cmd?
108
+ windows_cmd(puma_cmd, background)
109
+ else
110
+ nix_cmd(puma_cmd, background)
111
+ end
112
+ end
113
+
114
+ def nix_cmd(puma_cmd, background = false)
115
+ %(sh -c 'cd #{Dir.pwd} && #{puma_cmd} #{'&' if background}')
85
116
  end
86
117
 
87
- def windows_start_cmd
88
- %{cd "#{Dir.pwd}" && start "" /B cmd /C "puma #{cmd_opts}"}
118
+ def windows_cmd(puma_cmd, background = false)
119
+ %(cd "#{Dir.pwd}" && #{'start "" /B' if background} cmd /C "#{puma_cmd}")
89
120
  end
90
121
 
91
122
  def in_windows_cmd?
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module PumaVersion
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
2
  require 'guard/puma/runner'
3
- require 'pry'
4
3
 
5
4
  describe Guard::PumaRunner do
6
5
  let(:runner) { Guard::PumaRunner.new(options) }
7
6
  let(:environment) { 'development' }
8
7
  let(:port) { 4000 }
9
8
 
10
- let(:default_options) { { :environment => environment, :port => port } }
9
+ let(:default_options) { { environment: environment, port: port } }
11
10
  let(:options) { default_options }
12
11
 
13
12
  describe "#initialize" do
@@ -16,39 +15,61 @@ describe Guard::PumaRunner do
16
15
  end
17
16
  end
18
17
 
19
- %w(halt restart).each do |cmd|
18
+ %w[halt restart].each do |cmd|
20
19
  describe cmd do
21
- before do
22
- allow(runner).to receive(:build_uri).with(cmd).and_return(uri)
20
+ context "without pumactl" do
21
+ let(:options) { { pumactl: false } }
22
+
23
+ let(:uri) {
24
+ URI(
25
+ "http://#{runner.control_url}/#{cmd}?token=#{runner.control_token}"
26
+ )
27
+ }
28
+
29
+ it "#{cmd}s" do
30
+ expect(Net::HTTP).to receive(:get).with(uri).once
31
+ runner.public_send(cmd)
32
+ end
23
33
  end
24
- let(:uri) { URI("http://#{runner.control_url}/#{cmd}?token=#{runner.control_token}") }
25
- it "#{cmd}s" do
26
- expect(Net::HTTP).to receive(:get).with(uri).once
27
- runner.send(cmd.intern)
34
+
35
+ context "with pumactl" do
36
+ let(:options) { { pumactl: true } }
37
+
38
+ before do
39
+ allow(runner).to receive(:in_windows_cmd?).and_return(false)
40
+ end
41
+
42
+ let(:command) {
43
+ %(sh -c 'cd #{Dir.pwd} && pumactl #{runner.cmd_opts} #{cmd} ')
44
+ }
45
+
46
+ it "#{cmd}s" do
47
+ expect(Kernel).to receive(:system).with(command).once
48
+ runner.public_send(cmd)
49
+ end
28
50
  end
29
51
  end
30
52
  end
31
53
 
32
- describe '#start' do
54
+ describe "#start" do
33
55
  context "when on Windows" do
34
56
  before do
35
57
  allow(runner).to receive(:in_windows_cmd?).and_return(true)
36
- allow(runner).to receive(:windows_start_cmd).and_return("echo 'windows'")
37
58
  end
38
59
 
39
60
  it "runs the Windows command" do
40
- expect(Kernel).to receive(:system).with("echo 'windows'")
61
+ expect(Kernel).to receive(:system).with(%r{cmd /C ".+"})
41
62
  runner.start
42
63
  end
43
64
  end
44
65
 
45
66
  context "when on *nix" do
46
67
  before do
47
- allow(runner).to receive(:nix_start_cmd).and_return("echo 'nix'")
68
+ allow(runner).to receive(:in_windows_cmd?).and_return(false)
48
69
  end
49
70
 
50
71
  it "runs the *nix command" do
51
- expect(Kernel).to receive(:system).with("echo 'nix'")
72
+ expect(Kernel).to receive(:system).with(/sh -c '.+'/)
52
73
  runner.start
53
74
  end
54
75
  end
@@ -69,45 +90,127 @@ describe Guard::PumaRunner do
69
90
  let(:command) { runner.start }
70
91
 
71
92
  context "with config" do
72
- let(:options) {{ :config => path }}
73
93
  let(:path) { "/tmp/elephants" }
74
94
  let(:environment) { "special_dev" }
75
- it "adds path to command" do
76
- expect(runner.cmd_opts).to match("--config #{path}")
77
- end
78
95
 
79
- context "and additional options" do
80
- let(:options) {{ :config => path, :port => "4000", quiet: false, :environment => environment }}
81
- it "assumes options are set in config" do
96
+ context "without pumactl" do
97
+ let(:options) { { config: path, pumactl: false } }
98
+
99
+ it "adds path to command" do
82
100
  expect(runner.cmd_opts).to match("--config #{path}")
83
- expect(runner.cmd_opts).to match(/--control-token [0-9a-f]{10,}/)
84
- expect(runner.cmd_opts).to match("--control tcp")
85
- expect(runner.cmd_opts).to match("--environment #{environment}")
101
+ end
102
+
103
+ context "and additional options" do
104
+ let(:options) {
105
+ {
106
+ config: path, port: "4000",
107
+ quiet: false, environment: environment
108
+ }
109
+ }
110
+
111
+ it "assumes options are set in config" do
112
+ expect(runner.cmd_opts).to match("--config #{path}")
113
+ expect(runner.cmd_opts).to match(/--control-token [0-9a-f]{10,}/)
114
+ expect(runner.cmd_opts).to match("--control tcp")
115
+ expect(runner.cmd_opts).to match("--environment #{environment}")
116
+ end
117
+ end
118
+ end
119
+
120
+ context "with pumactl" do
121
+ let(:options) { { config: path, pumactl: true } }
122
+
123
+ it "adds path to command" do
124
+ expect(runner.cmd_opts).to match("--config-file #{path}")
125
+ end
126
+
127
+ context "and additional options" do
128
+ let(:options) {
129
+ {
130
+ pumactl: true,
131
+ config: path, port: "4000",
132
+ quiet: false
133
+ }
134
+ }
135
+
136
+ it "assumes options are set in config" do
137
+ expect(runner.cmd_opts).to match("--config-file #{path}")
138
+ expect(runner.cmd_opts).to match(/--control-token [0-9a-f]{10,}/)
139
+ expect(runner.cmd_opts).to match("--control-url tcp")
140
+ end
86
141
  end
87
142
  end
88
143
  end
89
144
 
90
145
  context "with bind" do
91
- let(:options) {{ :bind => uri }}
92
146
  let(:uri) { "tcp://foo" }
93
- it "adds uri option to command" do
94
- expect(runner.cmd_opts).to match("--bind #{uri}")
147
+
148
+ context "without pumactl" do
149
+ let(:options) { { pumactl: false, bind: uri } }
150
+
151
+ it "adds uri option to command" do
152
+ expect(runner.cmd_opts).to match("--bind #{uri}")
153
+ end
154
+ end
155
+
156
+ context "with pumactl" do
157
+ let(:options) { { pumactl: true, bind: uri } }
158
+
159
+ it "raises ArgumentError about incompatible options" do
160
+ expect(Guard::Compat::UI).to receive(:warning).with(/bind.+pumactl/)
161
+ runner.cmd_opts
162
+ end
95
163
  end
96
164
  end
97
165
 
98
166
  context "with control_token" do
99
- let(:options) {{ :control_token => token }}
100
167
  let(:token) { "imma-token" }
168
+ let(:options) { { control_token: token } }
169
+
101
170
  it "adds token to command" do
102
171
  expect(runner.cmd_opts).to match(/--control-token #{token}/)
103
172
  end
104
173
  end
105
174
 
106
175
  context "with threads" do
107
- let(:options) {{ :threads => threads }}
108
176
  let(:threads) { "13:42" }
109
- it "adds path to command" do
110
- expect(runner.cmd_opts).to match("--threads #{threads}")
177
+
178
+ context "without pumactl" do
179
+ let(:options) { { pumactl: false, threads: threads } }
180
+
181
+ it "adds threads option to command" do
182
+ expect(runner.cmd_opts).to match("--threads #{threads}")
183
+ end
184
+ end
185
+
186
+ context "with pumactl" do
187
+ let(:options) { { pumactl: true, threads: threads } }
188
+
189
+ it "raises ArgumentError about incompatible options" do
190
+ expect(Guard::Compat::UI).to receive(:warning).with(/threads.+pumactl/)
191
+ runner.cmd_opts
192
+ end
193
+ end
194
+ end
195
+
196
+ context "with environment" do
197
+ let(:environment) { "development" }
198
+
199
+ context "without pumactl" do
200
+ let(:options) { { pumactl: false, environment: environment } }
201
+
202
+ it "adds environment option to command" do
203
+ expect(runner.cmd_opts).to match("--environment #{environment}")
204
+ end
205
+ end
206
+
207
+ context "with pumactl" do
208
+ let(:options) { { pumactl: true, environment: environment } }
209
+
210
+ it "warns about incompatible options" do
211
+ expect(Guard::Compat::UI).to receive(:warning).with(/environment.+pumactl/)
212
+ runner.cmd_opts
213
+ end
111
214
  end
112
215
  end
113
216
  end
@@ -57,19 +57,20 @@ describe Guard::Puma do
57
57
  end
58
58
 
59
59
  describe '#start' do
60
-
61
- context 'start on start' do
60
+ context "start on start" do
62
61
  it "runs startup" do
63
- expect(guard).to receive(:start).once
62
+ expect(guard.runner).to receive(:start).once
63
+ expect(Guard::Compat::UI).to receive(:info).with(/Puma starting/)
64
64
  guard.start
65
65
  end
66
66
  end
67
67
 
68
- context 'no start on start' do
69
- let(:options) { { :start_on_start => false } }
68
+ context "no start on start" do
69
+ let(:options) { { start_on_start: false } }
70
70
 
71
- it "shows the right message and not run startup" do
72
- expect(guard.runner).to receive(:start).never
71
+ it "doesn't show the message and not run startup" do
72
+ expect(guard.runner).not_to receive(:start)
73
+ expect(Guard::Compat::UI).not_to receive(:info).with(/Puma starting/)
73
74
  guard.start
74
75
  end
75
76
  end
@@ -81,42 +82,45 @@ describe Guard::Puma do
81
82
 
82
83
  context "when no config option set" do
83
84
  it "contains port" do
84
- expect(Guard::UI).to receive(:info).with(/starting on port 4000/)
85
+ expect(Guard::Compat::UI).to receive(:info)
86
+ .with(/starting on port 4000/)
85
87
  guard.start
86
88
  end
87
89
  end
88
90
 
89
91
  context "when config option set" do
90
- let(:options) { { :config => 'config.rb' } }
92
+ let(:options) { { config: 'config.rb' } }
91
93
 
92
94
  it "doesn't contain port" do
93
- expect(Guard::UI).to receive(:info).with(/starting/)
95
+ expect(Guard::Compat::UI).to receive(:info).with(/starting/)
94
96
  guard.start
95
97
  end
96
98
  end
97
99
  end
98
100
  end
99
101
 
100
- describe '#reload' do
102
+ describe "#reload" do
103
+ let(:zero_restart_timeout) { { restart_timeout: 0 } }
104
+ let(:options) { zero_restart_timeout }
101
105
 
102
106
  before do
103
- expect(Guard::UI).to receive(:info).with('Restarting Puma...')
104
- expect(Guard::UI).to receive(:info).with('Puma restarted')
105
107
  allow(guard.runner).to receive(:restart).and_return(true)
108
+ allow_any_instance_of(Guard::PumaRunner).to receive(:halt)
106
109
  end
107
110
 
108
- let(:runner_stub) { allow_any_instance_of(Guard::PumaRunner).to receive(:halt) }
109
-
110
111
  context "with default options" do
111
112
  it "restarts and show the message" do
112
- expect(Guard::Notifier).to receive(:notify).with(
113
+ expect(Guard::Compat::UI).to receive(:info).with('Restarting Puma...')
114
+ expect(Guard::Compat::UI).to receive(:info).with('Puma restarted')
115
+
116
+ expect(Guard::Compat::UI).to receive(:notify).with(
113
117
  /restarting on port 4000/,
114
- hash_including(:title => "Restarting Puma...", :image => :pending)
118
+ hash_including(title: "Restarting Puma...", image: :pending)
115
119
  )
116
120
 
117
- expect(Guard::Notifier).to receive(:notify).with(
121
+ expect(Guard::Compat::UI).to receive(:notify).with(
118
122
  "Puma restarted on port 4000.",
119
- hash_including(:title => "Puma restarted!", :image => :success)
123
+ hash_including(title: "Puma restarted!", image: :success)
120
124
  )
121
125
 
122
126
  guard.reload
@@ -124,17 +128,20 @@ describe Guard::Puma do
124
128
  end
125
129
 
126
130
  context "with config option set" do
127
- let(:options) { { :config => "config.rb" } }
131
+ let(:options) { { config: "config.rb" }.merge!(zero_restart_timeout) }
128
132
 
129
133
  it "restarts and show the message" do
130
- expect(Guard::Notifier).to receive(:notify).with(
134
+ expect(Guard::Compat::UI).to receive(:info).with('Restarting Puma...')
135
+ expect(Guard::Compat::UI).to receive(:info).with('Puma restarted')
136
+
137
+ expect(Guard::Compat::UI).to receive(:notify).with(
131
138
  /restarting/,
132
- hash_including(:title => "Restarting Puma...", :image => :pending)
139
+ hash_including(title: "Restarting Puma...", image: :pending)
133
140
  )
134
141
 
135
- expect(Guard::Notifier).to receive(:notify).with(
142
+ expect(Guard::Compat::UI).to receive(:notify).with(
136
143
  "Puma restarted.",
137
- hash_including(:title => "Puma restarted!", :image => :success)
144
+ hash_including(title: "Puma restarted!", image: :success)
138
145
  )
139
146
 
140
147
  guard.reload
@@ -142,49 +149,95 @@ describe Guard::Puma do
142
149
  end
143
150
 
144
151
  context "with custom :notifications option" do
145
- let(:options) { { :notifications => [:restarted] } }
152
+ let(:options) {
153
+ { notifications: [:restarted] }.merge!(zero_restart_timeout)
154
+ }
146
155
 
147
156
  it "restarts and show the message only about restarted" do
148
- expect(Guard::Notifier).not_to receive(:notify).with(/restarting/)
149
- expect(Guard::Notifier).to receive(:notify).with(/restarted/, kind_of(Hash))
157
+ allow(Guard::Compat::UI).to receive(:info)
158
+
159
+ expect(Guard::Compat::UI).not_to receive(:notify).with(/restarting/)
160
+ expect(Guard::Compat::UI).to receive(:notify)
161
+ .with(/restarted/, kind_of(Hash))
150
162
 
151
163
  guard.reload
152
164
  end
153
165
  end
154
166
 
155
167
  context "with empty :notifications option" do
156
- let(:options) { { :notifications => [] } }
168
+ let(:options) { { notifications: [] }.merge!(zero_restart_timeout) }
157
169
 
158
170
  it "restarts and doesn't show the message" do
159
- expect(Guard::Notifier).not_to receive(:notify)
171
+ allow(Guard::Compat::UI).to receive(:info)
172
+
173
+ expect(Guard::Compat::UI).not_to receive(:notify)
160
174
 
161
175
  guard.reload
162
176
  end
163
177
  end
164
178
 
179
+ context "with :restart_timeout option" do
180
+ let(:restart_timeout) { 1.0 }
181
+ let(:options) { { restart_timeout: restart_timeout } }
182
+
183
+ before { sleep restart_timeout }
184
+
185
+ it "doesn't restarts during restart timeout" do
186
+ allow(Guard::Compat::UI).to receive(:info)
187
+ allow(Guard::Compat::UI).to receive(:notify)
188
+
189
+ expect(guard.runner).to receive(:restart).twice
190
+
191
+ guard.reload
192
+ sleep restart_timeout / 2
193
+ guard.reload
194
+ sleep restart_timeout
195
+ guard.reload
196
+ end
197
+ end
165
198
  end
166
199
 
167
- describe '#stop' do
200
+ describe "#stop" do
168
201
  context "with default options" do
169
202
  it "stops correctly with notification" do
170
- expect(Guard::Notifier).to receive(:notify).with('Until next time...', anything)
203
+ expect(Guard::Compat::UI).to receive(:notify)
204
+ .with('Until next time...', anything)
171
205
  expect(guard.runner).to receive(:halt).once
172
206
  guard.stop
173
207
  end
174
208
  end
175
209
 
176
210
  context "with custom :notifications option" do
177
- let(:options) { { :notifications => [] } }
211
+ let(:options) { { notifications: [] } }
178
212
 
179
213
  it "stops correctly without notification" do
180
- expect(Guard::Notifier).not_to receive(:notify)
214
+ expect(Guard::Compat::UI).not_to receive(:notify)
181
215
  expect(guard.runner).to receive(:halt).once
182
216
  guard.stop
183
217
  end
184
218
  end
219
+
220
+ context "start on start" do
221
+ it "stops correctly with notification" do
222
+ expect(guard.runner).to receive(:halt).once
223
+ expect(Guard::Compat::UI).to receive(:notify)
224
+ .with('Until next time...', anything)
225
+ guard.stop
226
+ end
227
+ end
228
+
229
+ context "no start on start" do
230
+ let(:options) { { start_on_start: false } }
231
+
232
+ it "doesn't show the message and doesn't halt" do
233
+ expect(guard.runner).not_to receive(:halt)
234
+ expect(Guard::Compat::UI).not_to receive(:notify)
235
+ guard.stop
236
+ end
237
+ end
185
238
  end
186
239
 
187
- describe '#run_on_changes' do
240
+ describe "#run_on_changes" do
188
241
  it "reloads on change" do
189
242
  expect(guard).to receive(:reload).once
190
243
  guard.run_on_changes([])
data/spec/spec_helper.rb CHANGED
@@ -11,4 +11,5 @@ RSpec.configure do |config|
11
11
  config.run_all_when_everything_filtered = true
12
12
  config.filter_run :focus
13
13
  config.mock_with :rspec
14
+ config.color = true
14
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-puma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-13 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -58,56 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.4'
61
+ version: '12'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.4'
68
+ version: '12'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.5.0
75
+ version: '3.7'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.5.0
82
+ version: '3.7'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 4.7.0
89
+ version: '4.7'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 4.7.0
97
- - !ruby/object:Gem::Dependency
98
- name: pry
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
96
+ version: '4.7'
111
97
  description:
112
98
  email:
113
99
  - jesse@jc00ke.com
@@ -150,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
136
  version: '0'
151
137
  requirements: []
152
138
  rubyforge_project:
153
- rubygems_version: 2.6.11
139
+ rubygems_version: 2.6.14
154
140
  signing_key:
155
141
  specification_version: 4
156
142
  summary: Restart puma when files change