From d21d36f64ca6d558920588b1c9d7590804f26bc3 Mon Sep 17 00:00:00 2001 From: Eito Katagiri Date: Wed, 31 Jul 2019 22:41:25 +0900 Subject: [PATCH] really fix when tmux is not installed or is not found When tmux cannot be find, `Shellany::Sheller.stdout('tmux -V')` returns `nil`, not empty string. --- lib/notiffany/notifier/tmux/client.rb | 2 +- spec/lib/notiffany/notifier/tmux_spec.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/notiffany/notifier/tmux/client.rb b/lib/notiffany/notifier/tmux/client.rb index b3eb517..1af361b 100644 --- a/lib/notiffany/notifier/tmux/client.rb +++ b/lib/notiffany/notifier/tmux/client.rb @@ -11,7 +11,7 @@ class << self def version begin Float(_capture("-V")[/\d+\.\d+/]) - rescue TypeError + rescue NoMethodError, TypeError raise Base::UnavailableError, "Could not find tmux" end end diff --git a/spec/lib/notiffany/notifier/tmux_spec.rb b/spec/lib/notiffany/notifier/tmux_spec.rb index f426697..5acb4d5 100644 --- a/spec/lib/notiffany/notifier/tmux_spec.rb +++ b/spec/lib/notiffany/notifier/tmux_spec.rb @@ -14,7 +14,16 @@ class Notifier describe ".version" do context "when tmux is not installed" do it "fails" do - allow(sheller).to receive(:stdout).and_return('') + allow(sheller).to receive(:stdout).and_return(nil) + expect do + described_class.version + end.to raise_error(Base::UnavailableError) + end + end + + context "when 'tmux -v' doesn't contain float-like string" do + it "fails" do + allow(sheller).to receive(:stdout).and_return('master') expect do described_class.version end.to raise_error(Base::UnavailableError)