diff --git a/lib/homesick/cli.rb b/lib/homesick/cli.rb index fdb5fba..3a308a9 100644 --- a/lib/homesick/cli.rb +++ b/lib/homesick/cli.rb @@ -19,8 +19,13 @@ module Homesick def initialize(args = [], options = {}, config = {}) super - self.shell = Thor::Shell::Color.new + # Check if git is installed + unless `git --version`.size > 0 + say_status :error, 'Git must be installed to use Homesick', :red + exit(1) + end # Hack in support for diffing symlinks + self.shell = Thor::Shell::Color.new class << shell def show_diff(destination, content) destination = Pathname.new(destination) diff --git a/spec/homesick_cli_spec.rb b/spec/homesick_cli_spec.rb index fc0fa3f..9a710f0 100644 --- a/spec/homesick_cli_spec.rb +++ b/spec/homesick_cli_spec.rb @@ -13,7 +13,7 @@ describe Homesick::CLI do before { allow(homesick).to receive(:repos_dir).and_return(castles) } - describe 'smoke test' do + describe 'smoke tests' do context 'when running bin/homesick' do before do bin_path = Pathname.new(__FILE__).parent.parent @@ -23,6 +23,17 @@ describe Homesick::CLI do expect(@output.length).to be > 0 end end + + context 'when git is not installed' do + before do + # The following line suppresses Thor warnings about overriding methods. + allow($stdout).to receive(:write).at_least(:once) + expect_any_instance_of(Homesick::CLI).to receive(:`).and_return('') + end + it 'should raise an exception when Git is not installed' do + Capture.stdout{ expect{Homesick::CLI.new}.to raise_error SystemExit } + end + end end describe 'clone' do