-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Committed improvements #35
Changes from 1 commit
c42be83
13192e2
9f5158d
a1b7729
651e3b3
533223b
dd6945b
67520e3
539b8fc
6973c6f
46637ce
f662b8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ def self.default_env | |
:start_on_start => true, | ||
:force_run => false, | ||
:timeout => 20, | ||
:restart_timeout => 1, | ||
:debugger => false, | ||
:notifications => %i[restarting restarted not_restarted stopped] | ||
} | ||
|
@@ -26,6 +27,7 @@ def initialize(options = {}) | |
@options = DEFAULT_OPTIONS.merge(options) | ||
@options[:port] = nil if @options.key?(:config) | ||
@runner = ::Guard::PumaRunner.new(@options) | ||
@last_restarted = Time.now | ||
end | ||
|
||
def start | ||
|
@@ -38,6 +40,8 @@ def start | |
end | ||
|
||
def reload | ||
return if Time.now - @last_restarted < options[:restart_timeout] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add parens to make the order of operations more clear? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sure. |
||
@last_restarted = Time.now | ||
Compat::UI.info "Restarting Puma..." | ||
if options[:notifications].include?(:restarting) | ||
Compat::UI.notify( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,15 +100,19 @@ | |
end | ||
|
||
describe "#reload" do | ||
let(:zero_restart_timeout) { { restart_timeout: 0 } } | ||
let(:options) { zero_restart_timeout } | ||
|
||
before do | ||
expect(Guard::Compat::UI).to receive(:info).with('Restarting Puma...') | ||
expect(Guard::Compat::UI).to receive(:info).with('Puma restarted') | ||
allow(guard.runner).to receive(:restart).and_return(true) | ||
allow_any_instance_of(Guard::PumaRunner).to receive(:halt) | ||
end | ||
|
||
context "with default options" do | ||
it "restarts and show the message" do | ||
expect(Guard::Compat::UI).to receive(:info).with('Restarting Puma...') | ||
expect(Guard::Compat::UI).to receive(:info).with('Puma restarted') | ||
|
||
expect(Guard::Compat::UI).to receive(:notify).with( | ||
/restarting on port 4000/, | ||
hash_including(title: "Restarting Puma...", image: :pending) | ||
|
@@ -124,9 +128,12 @@ | |
end | ||
|
||
context "with config option set" do | ||
let(:options) { { config: "config.rb" } } | ||
let(:options) { { config: "config.rb" }.merge!(zero_restart_timeout) } | ||
|
||
it "restarts and show the message" do | ||
expect(Guard::Compat::UI).to receive(:info).with('Restarting Puma...') | ||
expect(Guard::Compat::UI).to receive(:info).with('Puma restarted') | ||
|
||
expect(Guard::Compat::UI).to receive(:notify).with( | ||
/restarting/, | ||
hash_including(title: "Restarting Puma...", image: :pending) | ||
|
@@ -142,9 +149,13 @@ | |
end | ||
|
||
context "with custom :notifications option" do | ||
let(:options) { { notifications: [:restarted] } } | ||
let(:options) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a fan of the Semantic Rule so let's change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, no problem. |
||
{ notifications: [:restarted] }.merge!(zero_restart_timeout) | ||
end | ||
|
||
it "restarts and show the message only about restarted" do | ||
allow(Guard::Compat::UI).to receive(:info) | ||
|
||
expect(Guard::Compat::UI).not_to receive(:notify).with(/restarting/) | ||
expect(Guard::Compat::UI).to receive(:notify) | ||
.with(/restarted/, kind_of(Hash)) | ||
|
@@ -154,15 +165,36 @@ | |
end | ||
|
||
context "with empty :notifications option" do | ||
let(:options) { { notifications: [] } } | ||
let(:options) { { notifications: [] }.merge!(zero_restart_timeout) } | ||
|
||
it "restarts and doesn't show the message" do | ||
allow(Guard::Compat::UI).to receive(:info) | ||
|
||
expect(Guard::Compat::UI).not_to receive(:notify) | ||
|
||
guard.reload | ||
end | ||
end | ||
|
||
context "with :restart_timeout option" do | ||
let(:restart_timeout) { 1.0 } | ||
let(:options) { { restart_timeout: restart_timeout } } | ||
|
||
before { sleep restart_timeout } | ||
|
||
it "doesn't restarts during restart timeout" do | ||
allow(Guard::Compat::UI).to receive(:info) | ||
allow(Guard::Compat::UI).to receive(:notify) | ||
|
||
expect(guard.runner).to receive(:restart).twice | ||
|
||
guard.reload | ||
sleep restart_timeout / 2 | ||
guard.reload | ||
sleep restart_timeout | ||
guard.reload | ||
end | ||
end | ||
end | ||
|
||
describe "#stop" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍