Skip to content
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

Slightly improve syntax #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/guard/puma/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class PumaRunner

def initialize(options)
@control_token = options.delete(:control_token) { |_| ::Puma::Configuration.random_token }
@control = "localhost"
@control_port = (options.delete(:control_port) || '9293')
@control_url = "#{@control}:#{@control_port}"
@control_url = "localhost:#{@control_port}"
@quiet = options.delete(:quiet) { true }
@options = options

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/guard/puma/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:environment) { 'development' }
let(:port) { 4000 }

let(:default_options) { { :environment => environment, :port => port } }
let(:default_options) { { environment: environment, port: port } }
let(:options) { default_options }

describe "#initialize" do
Expand All @@ -16,7 +16,7 @@
end
end

%w(halt restart).each do |cmd|
%w[halt restart].each do |cmd|
describe cmd do
before do
allow(runner).to receive(:build_uri).with(cmd).and_return(uri)
Expand All @@ -29,7 +29,7 @@
end
end

describe '#start' do
describe "#start" do
context "when on Windows" do
before do
allow(runner).to receive(:in_windows_cmd?).and_return(true)
Expand Down
29 changes: 13 additions & 16 deletions spec/lib/guard/puma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@
end

describe '#start' do

context 'start on start' do
context "start on start" do
it "runs startup" do
expect(guard).to receive(:start).once
guard.start
end
end

context 'no start on start' do
let(:options) { { :start_on_start => false } }
context "no start on start" do
let(:options) { { start_on_start: false } }

it "shows the right message and not run startup" do
expect(guard.runner).to receive(:start).never
Expand All @@ -87,7 +86,7 @@
end

context "when config option set" do
let(:options) { { :config => 'config.rb' } }
let(:options) { { config: 'config.rb' } }

it "doesn't contain port" do
expect(Guard::UI).to receive(:info).with(/starting/)
Expand All @@ -98,51 +97,49 @@
end

describe '#reload' do

before do
expect(Guard::UI).to receive(:info).with('Restarting Puma...')
expect(Guard::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

let(:runner_stub) { allow_any_instance_of(Guard::PumaRunner).to receive(:halt) }

context "with default options" do
it "restarts and show the message" do
expect(Guard::Notifier).to receive(:notify).with(
/restarting on port 4000/,
hash_including(:title => "Restarting Puma...", :image => :pending)
hash_including(title: "Restarting Puma...", image: :pending)
)

expect(Guard::Notifier).to receive(:notify).with(
"Puma restarted on port 4000.",
hash_including(:title => "Puma restarted!", :image => :success)
hash_including(title: "Puma restarted!", image: :success)
)

guard.reload
end
end

context "with config option set" do
let(:options) { { :config => "config.rb" } }
let(:options) { { config: "config.rb" } }

it "restarts and show the message" do
expect(Guard::Notifier).to receive(:notify).with(
/restarting/,
hash_including(:title => "Restarting Puma...", :image => :pending)
hash_including(title: "Restarting Puma...", image: :pending)
)

expect(Guard::Notifier).to receive(:notify).with(
"Puma restarted.",
hash_including(:title => "Puma restarted!", :image => :success)
hash_including(title: "Puma restarted!", image: :success)
)

guard.reload
end
end

context "with custom :notifications option" do
let(:options) { { :notifications => [:restarted] } }
let(:options) { { notifications: [:restarted] } }

it "restarts and show the message only about restarted" do
expect(Guard::Notifier).not_to receive(:notify).with(/restarting/)
Expand All @@ -153,7 +150,7 @@
end

context "with empty :notifications option" do
let(:options) { { :notifications => [] } }
let(:options) { { notifications: [] } }

it "restarts and doesn't show the message" do
expect(Guard::Notifier).not_to receive(:notify)
Expand All @@ -174,7 +171,7 @@
end

context "with custom :notifications option" do
let(:options) { { :notifications => [] } }
let(:options) { { notifications: [] } }

it "stops correctly without notification" do
expect(Guard::Notifier).not_to receive(:notify)
Expand Down