hub_test.rb 4.9 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
  def test_clone_with_arguments_and_path
    input   = "clone --bare -o master -- resque"
    command = "git clone --bare -o master -- git://github.com/tpw/resque.git"
    assert_command input, command
  end

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  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

55 56 57 58 59 60 61 62 63 64 65
  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 已提交
66 67 68 69 70 71

  def test_normal_public_clone_with_path
    input   = "clone git://github.com/rtomayko/ron.git ron-dev"
    command = "git clone git://github.com/rtomayko/ron.git ron-dev"
    assert_command input, command
  end
72 73 74 75 76 77

  def test_normal_clone_from_path
    input   = "clone ./test"
    command = "git clone ./test"
    assert_command input, command
  end
78

C
Chris Wanstrath 已提交
79
  def test_private_remote
80
    input   = "remote add -p rtomayko"
C
Chris Wanstrath 已提交
81 82
    command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
    assert_command input, command
C
Chris Wanstrath 已提交
83 84 85
  end

  def test_public_remote
86
    input   = "remote add rtomayko"
C
Chris Wanstrath 已提交
87 88
    command = "git remote add rtomayko git://github.com/rtomayko/hub.git"
    assert_command input, command
C
Chris Wanstrath 已提交
89 90 91
  end

  def test_init
C
Chris Wanstrath 已提交
92 93
    h = Hub("init -g")
    assert_equal "git init", h.command
94 95 96 97 98 99 100 101 102
    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 已提交
103 104
  end

105 106 107 108 109 110
  def test_push_two
    h = Hub("push origin,staging cool-feature")
    assert_equal "git push origin cool-feature", h.command
    assert_equal "git push staging cool-feature", h.after
  end

C
Chris Wanstrath 已提交
111 112 113 114 115 116
  def test_push_more
    h = Hub("push origin,staging,qa cool-feature")
    assert_equal "git push origin cool-feature", h.command
    assert_equal "git push staging cool-feature; git push qa cool-feature", h.after
  end

C
Chris Wanstrath 已提交
117
  def test_version
118 119
    out = hub('--version')
    assert_includes "git version 1.6", out
C
Chris Wanstrath 已提交
120
    assert_includes "hub version 0.2", out
C
Chris Wanstrath 已提交
121
  end
C
Chris Wanstrath 已提交
122 123 124 125 126 127 128 129

  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 已提交
130 131 132 133

  def test_help_hub
    help_manpage = hub("help hub")
    assert_includes "git + hub = github", help_manpage
C
Chris Wanstrath 已提交
134
    assert_includes "$ git clone schacon/ticgit", help_manpage
C
Chris Wanstrath 已提交
135 136
    assert_includes "Chris Wanstrath :: chris@ozmm.org", help_manpage
    assert_includes <<-config, help_manpage
C
Chris Wanstrath 已提交
137
Use git-config(1) to display the currently configured GitHub username:
C
Chris Wanstrath 已提交
138 139 140 141 142 143 144 145 146 147 148
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
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

  def test_hub_open
    input   = "browse mojombo/bert"
    command = "http://github.com/mojombo/bert\n"
    assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
  end

  def test_hub_open_private
    input   = "browse -p bmizerany/sinatra"
    command = "https://github.com/bmizerany/sinatra\n"
    assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
  end

  def test_hub_open_self
    input   = "browse resque"
    command = "http://github.com/tpw/resque\n"
    assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
  end

  def test_hub_open_self_private
    input   = "browse -p github"
    command = "https://github.com/tpw/github\n"
    assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
  end
C
Chris Wanstrath 已提交
173
end