guard-puma 0.4.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +9 -0
- data/.travis.yml +8 -3
- data/CHANGES.md +27 -0
- data/README.md +5 -2
- data/guard-puma.gemspec +5 -5
- data/lib/guard/puma.rb +33 -15
- data/lib/guard/puma/runner.rb +70 -31
- data/lib/guard/puma/version.rb +1 -1
- data/spec/lib/guard/puma/runner_spec.rb +154 -30
- data/spec/lib/guard/puma_spec.rb +87 -34
- data/spec/spec_helper.rb +1 -0
- metadata +22 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c4882d80d8bb73e013141fc821e88c95a5cf8cf2c2cb1597de1d266951dda350
|
4
|
+
data.tar.gz: db041e9db3a6612ad08c77d10c40245675e41b4022366e36ac2a23b6390cc4a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742d39e52c73797a1bfae1d5744a3744a0ee13672ca5c950aa610739614f6647db02153935e72b264c53719aac2a0d1b3992dc5bad5545c48b802c4c0868d94f
|
7
|
+
data.tar.gz: f4e46ba7c2cfdbfb9726bcbf23099456efe4a22cc30b7424f27edaf21dc86a08bd7647e9a463ed99b9dfb302f341914054be89c0800f5c804cb487c42e522d73
|
data/.editorconfig
ADDED
data/.travis.yml
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.3
|
4
|
+
- 2.5.5
|
5
|
+
- 2.6.3
|
6
|
+
- 2.7.0-preview1
|
6
7
|
- rbx
|
7
|
-
- jruby-9.
|
8
|
+
- jruby-9.2.2.0
|
9
|
+
env:
|
10
|
+
- PUMA_VERSION="~> 5.0"
|
11
|
+
- PUMA_VERSION="~> 4.0"
|
8
12
|
matrix:
|
9
13
|
allow_failures:
|
10
14
|
- rvm: rbx
|
15
|
+
- rvm: 2.7.0-preview1
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 0.7.0
|
4
|
+
|
5
|
+
* Add MIT license identifier in gemspec. Via #45
|
6
|
+
* Remove support for MRI 2.2|3 and bump other versions
|
7
|
+
|
8
|
+
## 0.6.0
|
9
|
+
|
10
|
+
* Bump puma to 4.0
|
11
|
+
|
12
|
+
## 0.5.2
|
13
|
+
|
14
|
+
* Default config to `-` instead of `nil`. Fixes #38
|
15
|
+
|
16
|
+
## 0.5.1
|
17
|
+
|
18
|
+
* Detect and use `config/puma.rb` if present
|
19
|
+
|
20
|
+
## 0.5.0
|
21
|
+
|
22
|
+
* Add `:pumactl` option
|
23
|
+
* Add `:restart_timeout` option
|
24
|
+
* Don't stop Puma if it was not started by Guard
|
25
|
+
* Don't notify about start when no start
|
26
|
+
* Improve `guard-compat` using (https://github.com/guard/guard-compat#migrating-your-api-calls)
|
27
|
+
* Remove unused `pry` dependency
|
28
|
+
* Update versions of dependencies
|
29
|
+
|
3
30
|
## 0.4.1
|
4
31
|
|
5
32
|
* Improve notifications. Via #30
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# Guard::Puma
|
2
2
|
[](http://travis-ci.org/jc00ke/guard-puma)
|
3
|
-
[](https://gemnasium.com/jc00ke/guard-puma)
|
4
3
|
|
5
4
|
Restart Puma when some files change
|
6
5
|
|
@@ -33,17 +32,21 @@ end
|
|
33
32
|
|
34
33
|
* `:port` is the port number to run on (default `4000`)
|
35
34
|
* `:environment` is the environment to use (default `development`)
|
36
|
-
* `:start_on_start` will start the server when starting Guard (default `true`)
|
35
|
+
* `:start_on_start` will start the server when starting Guard and stop the server when reloading/stopping Guard (default `true`)
|
37
36
|
* `:force_run` kills any process that's holding open the listen port before attempting to (re)start Puma (default `false`).
|
38
37
|
* `:daemon` runs the server as a daemon, without any output to the terminal that ran `guard` (default `false`).
|
39
38
|
* `:quiet` runs the server in quiet mode, suppressing output (default `true`).
|
40
39
|
* `:debugger` runs the server with the debugger enabled (default `false`). Required ruby-debug gem.
|
41
40
|
* `:timeout` waits this number of seconds when restarting the Puma server before reporting there's a problem (default `20`).
|
41
|
+
* `:restart_timeout` waits this number of seconds before the next restarting the Puma server (default `1`).
|
42
42
|
* `:config` is the path to the Puma config file (optional)
|
43
43
|
* `:bind` is URI to bind to (tcp:// and unix:// only) (optional)
|
44
44
|
* `:control_token` is the token to use as authentication for the control server(optional)
|
45
45
|
* `:control_port` is the port to use for the control server(optional)
|
46
46
|
* `:threads` is the min:max number of threads to use. Defaults to 0:16 (optional)
|
47
|
+
* `:pumactl` manages the server via `pumactl` executable instead of `puma` (default `false`)
|
48
|
+
* Incompatible with options such as `port`, `environment`, `daemon`, `bind`, `threads`
|
49
|
+
* Use with `config` option is preferred.
|
47
50
|
* `:notifications` is the list of notification types that will be sent. Defaults to `[:restarting, :restarted, :not_restarted, :stopped]` (optional)
|
48
51
|
|
49
52
|
## Contributing
|
data/guard-puma.gemspec
CHANGED
@@ -6,6 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["jesse@jc00ke.com"]
|
7
7
|
gem.summary = %q{Restart puma when files change }
|
8
8
|
gem.homepage = "https://github.com/jc00ke/guard-puma"
|
9
|
+
gem.license = "MIT"
|
9
10
|
|
10
11
|
gem.files = `git ls-files`.split($\)
|
11
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -15,9 +16,8 @@ Gem::Specification.new do |gem|
|
|
15
16
|
gem.version = Guard::PumaVersion::VERSION
|
16
17
|
gem.add_dependency "guard", "~> 2.14"
|
17
18
|
gem.add_dependency "guard-compat", "~> 1.2"
|
18
|
-
gem.add_dependency "puma", "
|
19
|
-
gem.add_development_dependency "rake", "~>
|
20
|
-
gem.add_development_dependency "rspec", "~> 3.
|
21
|
-
gem.add_development_dependency "guard-rspec", "~> 4.7
|
22
|
-
gem.add_development_dependency "pry"
|
19
|
+
gem.add_dependency "puma", ENV["PUMA_VERSION"] || [">= 4.0", "< 6"]
|
20
|
+
gem.add_development_dependency "rake", "~> 12"
|
21
|
+
gem.add_development_dependency "rspec", "~> 3.7"
|
22
|
+
gem.add_development_dependency "guard-rspec", "~> 4.7"
|
23
23
|
end
|
data/lib/guard/puma.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
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
|
36
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/guard/puma/runner.rb
CHANGED
@@ -6,49 +6,50 @@ 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 = "
|
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 =
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
puma_options = {
|
20
|
+
puma_options_key(:config) => options.fetch(: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
|
+
elsif default_config_file_exists?
|
27
|
+
puma_options['--config'] = DEFAULT_CONFIG_FILE_PATH
|
26
28
|
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]
|
29
|
+
puma_options['--port'] = options[:port]
|
36
30
|
end
|
31
|
+
%i[bind threads environment]
|
32
|
+
.select { |opt| options[opt] }
|
33
|
+
.each do |opt|
|
34
|
+
if pumactl
|
35
|
+
Compat::UI.warning(
|
36
|
+
"`#{opt}` option is not compatible with `pumactl` option"
|
37
|
+
)
|
38
|
+
else
|
39
|
+
puma_options["--#{opt}"] = options[opt]
|
40
|
+
end
|
41
|
+
end
|
37
42
|
puma_options = puma_options.to_a.flatten
|
38
|
-
puma_options << '
|
43
|
+
puma_options << '--quiet' if @quiet
|
39
44
|
@cmd_opts = puma_options.join ' '
|
40
45
|
end
|
41
46
|
|
42
47
|
def start
|
43
|
-
|
44
|
-
Kernel.system windows_start_cmd
|
45
|
-
else
|
46
|
-
Kernel.system nix_start_cmd
|
47
|
-
end
|
48
|
+
Kernel.system build_command('start')
|
48
49
|
end
|
49
50
|
|
50
51
|
def halt
|
51
|
-
|
52
|
+
run_puma_command!('halt')
|
52
53
|
# server may not have been stopped correctly, but we are halting so who cares.
|
53
54
|
return true
|
54
55
|
end
|
@@ -68,8 +69,36 @@ module Guard
|
|
68
69
|
|
69
70
|
private
|
70
71
|
|
72
|
+
DEFAULT_CONFIG_FILE_PATH = "config/puma.rb".freeze
|
73
|
+
|
74
|
+
PUMA_OPTIONS_KEYS_BY_PUMACTL = {
|
75
|
+
true => {
|
76
|
+
config: '--config-file',
|
77
|
+
control_url: '--control-url'
|
78
|
+
}.freeze,
|
79
|
+
false => {
|
80
|
+
config: '--config',
|
81
|
+
control_url: '--control-url',
|
82
|
+
}.freeze
|
83
|
+
}.freeze
|
84
|
+
|
85
|
+
private_constant :PUMA_OPTIONS_KEYS_BY_PUMACTL
|
86
|
+
|
87
|
+
def default_config_file_exists?
|
88
|
+
File.exist?(DEFAULT_CONFIG_FILE_PATH)
|
89
|
+
end
|
90
|
+
|
91
|
+
def puma_options_key(key)
|
92
|
+
keys = PUMA_OPTIONS_KEYS_BY_PUMACTL[@pumactl]
|
93
|
+
keys.fetch(key) { |k| "--#{k.to_s.tr('_', '-')}" }
|
94
|
+
end
|
95
|
+
|
71
96
|
def run_puma_command!(cmd)
|
72
|
-
|
97
|
+
if pumactl
|
98
|
+
Kernel.system build_command(cmd)
|
99
|
+
else
|
100
|
+
Net::HTTP.get build_uri(cmd)
|
101
|
+
end
|
73
102
|
return true
|
74
103
|
rescue Errno::ECONNREFUSED => e
|
75
104
|
# server may not have been started correctly.
|
@@ -80,12 +109,22 @@ module Guard
|
|
80
109
|
URI "http://#{control_url}/#{cmd}?token=#{control_token}"
|
81
110
|
end
|
82
111
|
|
83
|
-
def
|
84
|
-
|
112
|
+
def build_command(cmd)
|
113
|
+
puma_cmd = "#{pumactl ? 'pumactl' : 'puma'} #{cmd_opts} #{cmd if pumactl}"
|
114
|
+
background = cmd == 'start'
|
115
|
+
if in_windows_cmd?
|
116
|
+
windows_cmd(puma_cmd, background)
|
117
|
+
else
|
118
|
+
nix_cmd(puma_cmd, background)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def nix_cmd(puma_cmd, background = false)
|
123
|
+
%(sh -c 'cd #{Dir.pwd} && #{puma_cmd} #{'&' if background}')
|
85
124
|
end
|
86
125
|
|
87
|
-
def
|
88
|
-
%
|
126
|
+
def windows_cmd(puma_cmd, background = false)
|
127
|
+
%(cd "#{Dir.pwd}" && #{'start "" /B' if background} cmd /C "#{puma_cmd}")
|
89
128
|
end
|
90
129
|
|
91
130
|
def in_windows_cmd?
|
data/lib/guard/puma/version.rb
CHANGED
@@ -1,54 +1,85 @@
|
|
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) { { :
|
9
|
+
let(:default_options) { { environment: environment, port: port } }
|
11
10
|
let(:options) { default_options }
|
12
11
|
|
13
12
|
describe "#initialize" do
|
14
13
|
it "sets options" do
|
15
14
|
expect(runner.options).to eq(options)
|
16
15
|
end
|
16
|
+
|
17
|
+
it "sets the command options" do
|
18
|
+
runner = described_class.new(options.merge(control_token: "abc"))
|
19
|
+
expect(runner.cmd_opts).to include("--config - ")
|
20
|
+
expect(runner.cmd_opts).to include("--control-token abc")
|
21
|
+
expect(runner.cmd_opts).to include("--control-url tcp://localhost:9293")
|
22
|
+
expect(runner.cmd_opts).to include("--port 4000")
|
23
|
+
expect(runner.cmd_opts).to include("--environment development")
|
24
|
+
expect(runner.cmd_opts).to include("--quiet")
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
|
-
%w
|
28
|
+
%w[halt restart].each do |cmd|
|
20
29
|
describe cmd do
|
21
|
-
|
22
|
-
|
30
|
+
context "without pumactl" do
|
31
|
+
let(:options) { { pumactl: false } }
|
32
|
+
|
33
|
+
let(:uri) {
|
34
|
+
URI(
|
35
|
+
"http://#{runner.control_url}/#{cmd}?token=#{runner.control_token}"
|
36
|
+
)
|
37
|
+
}
|
38
|
+
|
39
|
+
it "#{cmd}s" do
|
40
|
+
expect(Net::HTTP).to receive(:get).with(uri).once
|
41
|
+
runner.public_send(cmd)
|
42
|
+
end
|
23
43
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
44
|
+
|
45
|
+
context "with pumactl" do
|
46
|
+
let(:options) { { pumactl: true } }
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(runner).to receive(:in_windows_cmd?).and_return(false)
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:command) {
|
53
|
+
%(sh -c 'cd #{Dir.pwd} && pumactl #{runner.cmd_opts} #{cmd} ')
|
54
|
+
}
|
55
|
+
|
56
|
+
it "#{cmd}s" do
|
57
|
+
expect(Kernel).to receive(:system).with(command).once
|
58
|
+
runner.public_send(cmd)
|
59
|
+
end
|
28
60
|
end
|
29
61
|
end
|
30
62
|
end
|
31
63
|
|
32
|
-
describe
|
64
|
+
describe "#start" do
|
33
65
|
context "when on Windows" do
|
34
66
|
before do
|
35
67
|
allow(runner).to receive(:in_windows_cmd?).and_return(true)
|
36
|
-
allow(runner).to receive(:windows_start_cmd).and_return("echo 'windows'")
|
37
68
|
end
|
38
69
|
|
39
70
|
it "runs the Windows command" do
|
40
|
-
expect(Kernel).to receive(:system).with(
|
71
|
+
expect(Kernel).to receive(:system).with(%r{cmd /C ".+"})
|
41
72
|
runner.start
|
42
73
|
end
|
43
74
|
end
|
44
75
|
|
45
76
|
context "when on *nix" do
|
46
77
|
before do
|
47
|
-
allow(runner).to receive(:
|
78
|
+
allow(runner).to receive(:in_windows_cmd?).and_return(false)
|
48
79
|
end
|
49
80
|
|
50
81
|
it "runs the *nix command" do
|
51
|
-
expect(Kernel).to receive(:system).with(
|
82
|
+
expect(Kernel).to receive(:system).with(/sh -c '.+'/)
|
52
83
|
runner.start
|
53
84
|
end
|
54
85
|
end
|
@@ -69,45 +100,138 @@ describe Guard::PumaRunner do
|
|
69
100
|
let(:command) { runner.start }
|
70
101
|
|
71
102
|
context "with config" do
|
72
|
-
let(:options) {{ :config => path }}
|
73
103
|
let(:path) { "/tmp/elephants" }
|
74
104
|
let(:environment) { "special_dev" }
|
75
|
-
it "adds path to command" do
|
76
|
-
expect(runner.cmd_opts).to match("--config #{path}")
|
77
|
-
end
|
78
105
|
|
79
|
-
context "
|
80
|
-
let(:options) {{ :
|
106
|
+
context "without pumactl but with a default config file" do
|
107
|
+
let(:options) { { pumactl: false } }
|
108
|
+
|
81
109
|
it "assumes options are set in config" do
|
110
|
+
allow_any_instance_of(Guard::PumaRunner).
|
111
|
+
to receive(:default_config_file_exists?).
|
112
|
+
and_return(true)
|
113
|
+
expect(runner.cmd_opts).to match("--config config/puma.rb")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "without pumactl" do
|
118
|
+
let(:options) { { config: path, pumactl: false } }
|
119
|
+
|
120
|
+
it "adds path to command" do
|
82
121
|
expect(runner.cmd_opts).to match("--config #{path}")
|
83
|
-
|
84
|
-
|
85
|
-
|
122
|
+
end
|
123
|
+
|
124
|
+
context "and additional options" do
|
125
|
+
let(:options) {
|
126
|
+
{
|
127
|
+
config: path, port: "4000",
|
128
|
+
quiet: false, environment: environment
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
it "assumes options are set in config" do
|
133
|
+
expect(runner.cmd_opts).to match("--config #{path}")
|
134
|
+
expect(runner.cmd_opts).to match(/--control-token [0-9a-f]{10,}/)
|
135
|
+
expect(runner.cmd_opts).to match("--control-url tcp")
|
136
|
+
expect(runner.cmd_opts).to match("--environment #{environment}")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "with pumactl" do
|
142
|
+
let(:options) { { config: path, pumactl: true } }
|
143
|
+
|
144
|
+
it "adds path to command" do
|
145
|
+
expect(runner.cmd_opts).to match("--config-file #{path}")
|
146
|
+
end
|
147
|
+
|
148
|
+
context "and additional options" do
|
149
|
+
let(:options) {
|
150
|
+
{
|
151
|
+
pumactl: true,
|
152
|
+
config: path, port: "4000",
|
153
|
+
quiet: false
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
it "assumes options are set in config" do
|
158
|
+
expect(runner.cmd_opts).to match("--config-file #{path}")
|
159
|
+
expect(runner.cmd_opts).to match(/--control-token [0-9a-f]{10,}/)
|
160
|
+
expect(runner.cmd_opts).to match("--control-url tcp")
|
161
|
+
end
|
86
162
|
end
|
87
163
|
end
|
88
164
|
end
|
89
165
|
|
90
166
|
context "with bind" do
|
91
|
-
let(:options) {{ :bind => uri }}
|
92
167
|
let(:uri) { "tcp://foo" }
|
93
|
-
|
94
|
-
|
168
|
+
|
169
|
+
context "without pumactl" do
|
170
|
+
let(:options) { { pumactl: false, bind: uri } }
|
171
|
+
|
172
|
+
it "adds uri option to command" do
|
173
|
+
expect(runner.cmd_opts).to match("--bind #{uri}")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "with pumactl" do
|
178
|
+
let(:options) { { pumactl: true, bind: uri } }
|
179
|
+
|
180
|
+
it "raises ArgumentError about incompatible options" do
|
181
|
+
expect(Guard::Compat::UI).to receive(:warning).with(/bind.+pumactl/)
|
182
|
+
runner.cmd_opts
|
183
|
+
end
|
95
184
|
end
|
96
185
|
end
|
97
186
|
|
98
187
|
context "with control_token" do
|
99
|
-
let(:options) {{ :control_token => token }}
|
100
188
|
let(:token) { "imma-token" }
|
189
|
+
let(:options) { { control_token: token } }
|
190
|
+
|
101
191
|
it "adds token to command" do
|
102
192
|
expect(runner.cmd_opts).to match(/--control-token #{token}/)
|
103
193
|
end
|
104
194
|
end
|
105
195
|
|
106
196
|
context "with threads" do
|
107
|
-
let(:options) {{ :threads => threads }}
|
108
197
|
let(:threads) { "13:42" }
|
109
|
-
|
110
|
-
|
198
|
+
|
199
|
+
context "without pumactl" do
|
200
|
+
let(:options) { { pumactl: false, threads: threads } }
|
201
|
+
|
202
|
+
it "adds threads option to command" do
|
203
|
+
expect(runner.cmd_opts).to match("--threads #{threads}")
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "with pumactl" do
|
208
|
+
let(:options) { { pumactl: true, threads: threads } }
|
209
|
+
|
210
|
+
it "raises ArgumentError about incompatible options" do
|
211
|
+
expect(Guard::Compat::UI).to receive(:warning).with(/threads.+pumactl/)
|
212
|
+
runner.cmd_opts
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "with environment" do
|
218
|
+
let(:environment) { "development" }
|
219
|
+
|
220
|
+
context "without pumactl" do
|
221
|
+
let(:options) { { pumactl: false, environment: environment } }
|
222
|
+
|
223
|
+
it "adds environment option to command" do
|
224
|
+
expect(runner.cmd_opts).to match("--environment #{environment}")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context "with pumactl" do
|
229
|
+
let(:options) { { pumactl: true, environment: environment } }
|
230
|
+
|
231
|
+
it "warns about incompatible options" do
|
232
|
+
expect(Guard::Compat::UI).to receive(:warning).with(/environment.+pumactl/)
|
233
|
+
runner.cmd_opts
|
234
|
+
end
|
111
235
|
end
|
112
236
|
end
|
113
237
|
end
|
data/spec/lib/guard/puma_spec.rb
CHANGED
@@ -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
|
69
|
-
let(:options) { { :
|
68
|
+
context "no start on start" do
|
69
|
+
let(:options) { { start_on_start: false } }
|
70
70
|
|
71
|
-
it "
|
72
|
-
expect(guard.runner).
|
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)
|
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) { { :
|
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
|
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::
|
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(:
|
118
|
+
hash_including(title: "Restarting Puma...", image: :pending)
|
115
119
|
)
|
116
120
|
|
117
|
-
expect(Guard::
|
121
|
+
expect(Guard::Compat::UI).to receive(:notify).with(
|
118
122
|
"Puma restarted on port 4000.",
|
119
|
-
hash_including(:
|
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) { { :
|
131
|
+
let(:options) { { config: "config.rb" }.merge!(zero_restart_timeout) }
|
128
132
|
|
129
133
|
it "restarts and show the message" do
|
130
|
-
expect(Guard::
|
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(:
|
139
|
+
hash_including(title: "Restarting Puma...", image: :pending)
|
133
140
|
)
|
134
141
|
|
135
|
-
expect(Guard::
|
142
|
+
expect(Guard::Compat::UI).to receive(:notify).with(
|
136
143
|
"Puma restarted.",
|
137
|
-
hash_including(:
|
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) {
|
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
|
-
|
149
|
-
|
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) { { :
|
168
|
+
let(:options) { { notifications: [] }.merge!(zero_restart_timeout) }
|
157
169
|
|
158
170
|
it "restarts and doesn't show the message" do
|
159
|
-
|
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
|
200
|
+
describe "#stop" do
|
168
201
|
context "with default options" do
|
169
202
|
it "stops correctly with notification" do
|
170
|
-
expect(Guard::
|
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) { { :
|
211
|
+
let(:options) { { notifications: [] } }
|
178
212
|
|
179
213
|
it "stops correctly without notification" do
|
180
|
-
expect(Guard::
|
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
|
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
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
|
+
version: 0.7.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:
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -42,72 +42,64 @@ dependencies:
|
|
42
42
|
name: puma
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
- - "<"
|
46
49
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
50
|
+
version: '6'
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- - "
|
55
|
+
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
57
|
+
version: '4.0'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '6'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '12'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
74
|
+
version: '12'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rspec
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
79
|
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
81
|
+
version: '3.7'
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
86
|
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
88
|
+
version: '3.7'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
90
|
name: guard-rspec
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: 4.7
|
95
|
+
version: '4.7'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
100
|
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: 4.7
|
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'
|
102
|
+
version: '4.7'
|
111
103
|
description:
|
112
104
|
email:
|
113
105
|
- jesse@jc00ke.com
|
@@ -115,6 +107,7 @@ executables: []
|
|
115
107
|
extensions: []
|
116
108
|
extra_rdoc_files: []
|
117
109
|
files:
|
110
|
+
- ".editorconfig"
|
118
111
|
- ".gitignore"
|
119
112
|
- ".travis.yml"
|
120
113
|
- CHANGES.md
|
@@ -132,7 +125,8 @@ files:
|
|
132
125
|
- spec/lib/guard/puma_spec.rb
|
133
126
|
- spec/spec_helper.rb
|
134
127
|
homepage: https://github.com/jc00ke/guard-puma
|
135
|
-
licenses:
|
128
|
+
licenses:
|
129
|
+
- MIT
|
136
130
|
metadata: {}
|
137
131
|
post_install_message:
|
138
132
|
rdoc_options: []
|
@@ -149,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
143
|
- !ruby/object:Gem::Version
|
150
144
|
version: '0'
|
151
145
|
requirements: []
|
152
|
-
|
153
|
-
rubygems_version: 2.6.11
|
146
|
+
rubygems_version: 3.1.2
|
154
147
|
signing_key:
|
155
148
|
specification_version: 4
|
156
149
|
summary: Restart puma when files change
|