hub_test.rb 3.2 KB
Newer Older
1 2
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'helper'
C
Chris Wanstrath 已提交
3 4

class HubTest < Test::Unit::TestCase
5 6 7 8
  def setup
    Hub::Commands::USER.replace("tpw")
  end

C
Chris Wanstrath 已提交
9
  def test_private_clone
C
Chris Wanstrath 已提交
10 11 12
    input   = "clone -p rtomayko/ron"
    command = "git clone git@github.com:rtomayko/ron.git"
    assert_command input, command
C
Chris Wanstrath 已提交
13 14 15
  end

  def test_public_clone
C
Chris Wanstrath 已提交
16 17 18
    input   = "clone rtomayko/ron"
    command = "git clone git://github.com/rtomayko/ron.git"
    assert_command input, command
C
Chris Wanstrath 已提交
19 20
  end

21 22 23 24 25 26 27 28 29 30 31 32
  def test_your_private_clone
    input   = "clone -p resque"
    command = "git clone git@github.com:tpw/resque.git"
    assert_command input, command
  end

  def test_your_public_clone
    input   = "clone resque"
    command = "git clone git://github.com/tpw/resque.git"
    assert_command input, command
  end

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  def test_your_private_clone_fails_without_config
    out = hub("clone -p mustache") do
      Hub::Commands::USER.replace("")
    end

    assert_equal "** No GitHub user set. See http://github.com/guides/local-github-config\n", out
  end

  def test_your_public_clone_fails_without_config
    out = hub("clone mustache") do
      Hub::Commands::USER.replace("")
    end

    assert_equal "** No GitHub user set. See http://github.com/guides/local-github-config\n", out
  end

49 50 51 52 53 54 55 56 57 58 59 60
  def test_private_clone_left_alone
    input   = "clone git@github.com:rtomayko/ron.git"
    command = "git clone git@github.com:rtomayko/ron.git"
    assert_command input, command
  end

  def test_public_clone_left_alone
    input   = "clone git://github.com/rtomayko/ron.git"
    command = "git clone git://github.com/rtomayko/ron.git"
    assert_command input, command
  end

C
Chris Wanstrath 已提交
61
  def test_private_remote
62
    input   = "remote add -p rtomayko"
C
Chris Wanstrath 已提交
63 64
    command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
    assert_command input, command
C
Chris Wanstrath 已提交
65 66 67
  end

  def test_public_remote
68
    input   = "remote add rtomayko"
C
Chris Wanstrath 已提交
69 70
    command = "git remote add rtomayko git://github.com/rtomayko/hub.git"
    assert_command input, command
C
Chris Wanstrath 已提交
71 72 73
  end

  def test_init
C
Chris Wanstrath 已提交
74 75
    h = Hub("init -g")
    assert_equal "git init", h.command
76 77 78 79 80 81 82 83 84
    assert_equal "git remote add origin git@github.com:tpw/hub.git", h.after
  end

  def test_init_no_login
    out = hub("init -g") do
      Hub::Commands::USER.replace("")
    end

    assert_equal "** No GitHub user set. See http://github.com/guides/local-github-config\n", out
C
Chris Wanstrath 已提交
85 86 87
  end

  def test_version
88 89
    out = hub('--version')
    assert_includes "git version 1.6", out
C
0.1.1  
Chris Wanstrath 已提交
90
    assert_includes "hub version 0.1", out
C
Chris Wanstrath 已提交
91
  end
C
Chris Wanstrath 已提交
92 93 94 95 96 97 98 99

  def test_help
    assert_equal Hub::Commands.improved_help_text, hub("help")
  end

  def test_help_by_default
    assert_equal Hub::Commands.improved_help_text, hub("")
  end
C
Chris Wanstrath 已提交
100 101 102 103

  def test_help_hub
    help_manpage = hub("help hub")
    assert_includes "git + hub = github", help_manpage
C
Chris Wanstrath 已提交
104
    assert_includes "Writes shell aliasing code", help_manpage
C
Chris Wanstrath 已提交
105 106
    assert_includes "Chris Wanstrath :: chris@ozmm.org", help_manpage
    assert_includes <<-config, help_manpage
C
Chris Wanstrath 已提交
107
Use git-config(1) to display the currently configured GitHub username:
C
Chris Wanstrath 已提交
108 109 110 111 112 113 114 115 116 117 118
config
  end

  def test_help_hub_no_groff
    help_manpage = hub("help hub") do
      Hub::Commands.class_eval do
        def groff?; false end
      end
    end
    assert_equal "** Can't find groff(1)\n", help_manpage
  end
C
Chris Wanstrath 已提交
119
end