hub_test.rb 2.6 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
C
terse  
Chris Wanstrath 已提交
88
    assert_equal "git version 1.6.4.2\nhub version 0.1.0\n", hub('--version')
C
Chris Wanstrath 已提交
89
  end
C
Chris Wanstrath 已提交
90 91 92 93 94 95 96 97

  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 已提交
98
end