From 988f2dd13ec8c342df7149f8f98c7c36db3565ba Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Fri, 2 Feb 2018 12:00:56 +0300 Subject: [PATCH] Slightly improve syntax --- lib/guard/puma/runner.rb | 3 +-- spec/lib/guard/puma/runner_spec.rb | 6 +++--- spec/lib/guard/puma_spec.rb | 29 +++++++++++++---------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/guard/puma/runner.rb b/lib/guard/puma/runner.rb index 7e96f24..6ca37d5 100644 --- a/lib/guard/puma/runner.rb +++ b/lib/guard/puma/runner.rb @@ -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 diff --git a/spec/lib/guard/puma/runner_spec.rb b/spec/lib/guard/puma/runner_spec.rb index 46f4792..21e0281 100644 --- a/spec/lib/guard/puma/runner_spec.rb +++ b/spec/lib/guard/puma/runner_spec.rb @@ -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 @@ -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) @@ -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) diff --git a/spec/lib/guard/puma_spec.rb b/spec/lib/guard/puma_spec.rb index 1ac9a23..addb104 100644 --- a/spec/lib/guard/puma_spec.rb +++ b/spec/lib/guard/puma_spec.rb @@ -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 @@ -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/) @@ -98,25 +97,23 @@ 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 @@ -124,17 +121,17 @@ 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 @@ -142,7 +139,7 @@ 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/) @@ -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) @@ -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)