diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 44ce83bcc8d5bf2b56c31f42d1cd2bdabf40763e..583f00d2659003b78ef13701e654f05b1e47cf82 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -89,7 +89,17 @@ module Hub 'fish' => 'alias git hub' } - shell = args[1] + if shell = args[1] + puts "Run this in your shell to start using `hub` as `git`:" + print " " + else + puts "usage: hub install SHELL", "" + puts "known shells:" + shells.map { |key, _| key }.sort.each do |key| + puts " " + key + end + exit + end if shells[shell] puts shells[shell] @@ -162,7 +172,7 @@ help # All calls to `puts` in after hooks or commands are paged, # git-style. - def puts(content) + def puts(*args) page_stdout super end diff --git a/test/helper.rb b/test/helper.rb index 9b4258f8c5638d05c1ca71cccf6108b412c5a55b..dc4561e9f769ec82a4ee76182f3b98cfd4a5fe01 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -44,4 +44,25 @@ class Test::Unit::TestCase def assert_command(input, expected) assert_equal expected, Hub(input).command end + + # Asserts that `hub` will show a specific installation command for a + # specific shell. + # + # e.g. + # assert_install_command "sh", "alias git=hub" + # + # Here we are saying that this: + # $ hub install sh + # Should display this: + # Run this in your shell to start using `hub` as `git`: + # alias git=hub + def assert_install_command(shell, command) + expected = "Run this in your shell to start using `hub` as `git`:\n %s\n" + assert_equal(expected % command, hub("install #{shell}")) + end + + # Asserts that `haystack` includes `needle`. + def assert_includes(needle, haystack) + assert haystack.include?(needle) + end end diff --git a/test/install_test.rb b/test/install_test.rb index ac422886ea2e41e47adf982ec3c688f7469104a7..2c26af52582d6aae410c20de5e156882733bbf49 100644 --- a/test/install_test.rb +++ b/test/install_test.rb @@ -2,27 +2,36 @@ $LOAD_PATH.unshift File.dirname(__FILE__) require 'helper' class InstallTest < Test::Unit::TestCase + def test_install + instructions = hub("install") + assert_includes "bash", instructions + assert_includes "sh", instructions + assert_includes "csh", instructions + assert_includes "zsh", instructions + assert_includes "fish", instructions + end + def test_install_bash - assert_equal "alias git=hub\n", hub("install bash") + assert_install_command "bash", "alias git=hub" end def test_install_sh - assert_equal "alias git=hub\n", hub("install sh") + assert_install_command "sh", "alias git=hub" end def test_install_zsh - assert_equal "alias git=hub\n", hub("install zsh") + assert_install_command "zsh", "alias git=hub" end def test_install_csh - assert_equal "alias git hub\n", hub("install csh") + assert_install_command "csh", "alias git hub" end def test_install_fish - assert_equal "alias git hub\n", hub("install fish") + assert_install_command "fish", "alias git hub" end def test_install_blah - assert_equal "fatal: never heard of `blah'\n", hub("install blah") + assert_install_command "blah", "fatal: never heard of `blah'" end end