From 60868ea2a131da24e9d66858dfb12c678fa9be0d Mon Sep 17 00:00:00 2001 From: Yuji Nakayama Date: Sun, 11 Jun 2017 09:12:00 +0900 Subject: [PATCH] Refactor launchy option --- lib/guard/rubocop/runner.rb | 6 +++--- spec/guard/rubocop/runner_spec.rb | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/guard/rubocop/runner.rb b/lib/guard/rubocop/runner.rb index dab019b..169dd67 100644 --- a/lib/guard/rubocop/runner.rb +++ b/lib/guard/rubocop/runner.rb @@ -128,10 +128,10 @@ def pluralize(number, thing, options = {}) end def open_launchy - return unless @options[:launchy] + return unless (output_path = @options[:launchy]) + return unless File.exist?(output_path) require 'launchy' - pn = Pathname.new(@options[:launchy]) - ::Launchy.open(@options[:launchy]) if pn.exist? + ::Launchy.open(output_path) end end end diff --git a/spec/guard/rubocop/runner_spec.rb b/spec/guard/rubocop/runner_spec.rb index 9b092ea..50354f3 100644 --- a/spec/guard/rubocop/runner_spec.rb +++ b/spec/guard/rubocop/runner_spec.rb @@ -92,8 +92,7 @@ let(:options) { { launchy: 'launchy_path' } } before do - allow(Pathname).to receive(:new) - .with('launchy_path') { double(exist?: true) } + allow(File).to receive(:exist?).with('launchy_path').and_return(true) end it 'opens Launchy' do