Permalink
Browse files

rewrite `clone`, `remote add`, `submodule add` tests as cukes

  • Loading branch information...
1 parent 8dd8afa commit 501e20b8d7f029c5e54ccb800b938808b61672f2 @mislav mislav committed May 4, 2012
Showing with 280 additions and 272 deletions.
  1. +91 −0 features/clone.feature
  2. +100 −0 features/remote_add.feature
  3. +68 −0 features/steps.rb
  4. +21 −0 features/submodule_add.feature
  5. +0 −272 test/hub_test.rb
View
91 features/clone.feature
@@ -0,0 +1,91 @@
+Feature: hub clone
+ Scenario: Clone a public repo
+ When I successfully run `hub clone rtomayko/ronn`
+ Then it should clone "git://github.com/rtomayko/ronn.git"
+ And there should be no output
+
+ Scenario: Clone a public repo with period in name
+ When I successfully run `hub clone hookio/hook.js`
+ Then it should clone "git://github.com/hookio/hook.js.git"
+ And there should be no output
+
+ Scenario: Clone a public repo with HTTPS
+ Given HTTPS is preferred
+ When I successfully run `hub clone rtomayko/ronn`
+ Then it should clone "https://github.com/rtomayko/ronn.git"
+ And there should be no output
+
+ Scenario: Clone command aliased
+ When I successfully run `git config --global alias.c "clone --bare"`
+ And I successfully run `hub c rtomayko/ronn`
+ Then "git clone --bare git://github.com/rtomayko/ronn.git" should be run
+ And there should be no output
+
+ Scenario: Unchanged public clone
+ When I successfully run `hub clone git://github.com/rtomayko/ronn.git`
+ Then the git command should be unchanged
+
+ Scenario: Unchanged public clone with path
+ When I successfully run `hub clone git://github.com/rtomayko/ronn.git ronnie`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Unchanged private clone
+ When I successfully run `hub clone git@github.com:rtomayko/ronn.git`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Unchanged clone with complex arguments
+ When I successfully run `hub clone --template=one/two git://github.com/defunkt/resque.git --origin master resquetastic`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Unchanged local clone
+ When I successfully run `hub clone ./dotfiles`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Unchanged local clone with destination
+ When I successfully run `hub clone -l . ../copy`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Unchanged clone with host alias
+ When I successfully run `hub clone shortcut:git/repo.git`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Preview cloning a private repo
+ When I successfully run `hub --noop clone -p rtomayko/ronn`
+ Then the output should contain exactly "git clone git@github.com:rtomayko/ronn.git\n"
+ But nothing should be run
+
+ Scenario: Clone a private repo
+ When I successfully run `hub clone -p rtomayko/ronn`
+ Then it should clone "git@github.com:rtomayko/ronn.git"
+ And there should be no output
+
+ Scenario: Clone my repo
+ Given I am "mislav" on GitHub.com
+ When I successfully run `hub clone dotfiles`
+ Then it should clone "git@github.com:mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Clone my repo with arguments
+ Given I am "mislav" on GitHub.com
+ When I successfully run `hub clone --bare -o master dotfiles`
+ Then "git clone --bare -o master git@github.com:mislav/dotfiles.git" should be run
+ And there should be no output
+
+ Scenario: Clone my Enterprise repo
+ Given I am "mifi" on git.my.org
+ And $GITHUB_HOST is "git.my.org"
+ When I successfully run `hub clone myrepo`
+ Then it should clone "git@git.my.org:mifi/myrepo.git"
+ And there should be no output
+
+ Scenario: Clone from existing directory is a local clone
+ Given a directory named "dotfiles"
+ When I successfully run `hub clone dotfiles`
+ Then the git command should be unchanged
+ And there should be no output
View
100 features/remote_add.feature
@@ -0,0 +1,100 @@
+Feature: hub remote add
+ Background:
+ Given I am in "dotfiles" git repo
+
+ Scenario: Add origin remote for my own repo
+ Given I am "mislav" on GitHub.com
+ And there are no remotes
+ When I successfully run `hub remote add origin`
+ Then the url for "origin" should be "git://github.com/mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Add private origin remote for my own repo
+ Given I am "mislav" on GitHub.com
+ And there are no remotes
+ When I successfully run `hub remote add -p origin`
+ Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Unchanged public remote add
+ When I successfully run `hub remote add origin http://github.com/defunkt/resque.git`
+ Then the url for "origin" should be "http://github.com/defunkt/resque.git"
+ And there should be no output
+
+ Scenario: Unchanged private remote add
+ When I successfully run `hub remote add origin git@github.com:defunkt/resque.git`
+ Then the url for "origin" should be "git@github.com:defunkt/resque.git"
+ And there should be no output
+
+ Scenario: Unchanged local path remote add
+ When I successfully run `hub remote add myremote ./path`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Unchanged local absolute path remote add
+ When I successfully run `hub remote add myremote /path`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Unchanged remote add with host alias
+ When I successfully run `hub remote add myremote server:/git/repo.git`
+ Then the git command should be unchanged
+ And there should be no output
+
+ Scenario: Add new remote for Enterprise repo
+ Given "git.my.org" is a whitelisted Enterprise host
+ And the "origin" remote has url "git@git.my.org:mislav/topsekrit.git"
+ When I successfully run `hub remote add another`
+ Then the url for "another" should be "git@git.my.org:another/topsekrit.git"
+ And there should be no output
+
+ Scenario: Add public remote
+ When I successfully run `hub remote add mislav`
+ Then the url for "mislav" should be "git://github.com/mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Add private remote
+ When I successfully run `hub remote add -p mislav`
+ Then the url for "mislav" should be "git@github.com:mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Add remote with arguments
+ When I successfully run `hub remote add -f mislav`
+ Then "git remote add -f mislav git://github.com/mislav/dotfiles.git" should be run
+ And there should be no output
+
+ Scenario: Add HTTPS protocol remote
+ Given HTTPS is preferred
+ When I successfully run `hub remote add mislav`
+ Then the url for "mislav" should be "https://github.com/mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Add named public remote
+ When I successfully run `hub remote add mm mislav`
+ Then the url for "mm" should be "git://github.com/mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Add public remote including repo name
+ When I successfully run `hub remote add mislav/dotfilez.js`
+ Then the url for "mislav" should be "git://github.com/mislav/dotfilez.js.git"
+ And there should be no output
+
+ Scenario: Add named public remote including repo name
+ When I successfully run `hub remote add mm mislav/dotfilez.js`
+ Then the url for "mm" should be "git://github.com/mislav/dotfilez.js.git"
+ And there should be no output
+
+ Scenario: Add named private remote
+ When I successfully run `hub remote add -p mm mislav`
+ Then the url for "mm" should be "git@github.com:mislav/dotfiles.git"
+ And there should be no output
+
+ Scenario: Add private remote including repo name
+ When I successfully run `hub remote add -p mislav/dotfilez.js`
+ Then the url for "mislav" should be "git@github.com:mislav/dotfilez.js.git"
+ And there should be no output
+
+ Scenario: Add named private remote including repo name
+ When I successfully run `hub remote add -p mm mislav/dotfilez.js`
+ Then the url for "mm" should be "git@github.com:mislav/dotfilez.js.git"
+ And there should be no output
View
68 features/steps.rb
@@ -0,0 +1,68 @@
+Given /^HTTPS is preferred$/ do
+ run_silent %(git config --global hub.protocol https)
+end
+
+Given /^there are no remotes$/ do
+ run_silent('git remote').should be_empty
+end
+
+Given /^"([^"]*)" is a whitelisted Enterprise host$/ do |host|
+ run_silent %(git config --global --add hub.host "#{host}")
+end
+
+Given /^the "([^"]*)" remote has url "([^"]*)"$/ do |remote_name, url|
+ run_silent %(git remote add #{remote_name} "#{url}")
+end
+
+Given /^I am "([^"]*)" on ([\w.-]+)$/ do |name, host|
+ edit_hub_config do |cfg|
+ cfg[host.downcase] = [{'user' => name}]
+ end
+end
+
+Given /^\$(\w+) is "([^"]*)"$/ do |name, value|
+ set_env name, value
+end
+
+Given /^I am in "([^"]*)" git repo$/ do |dir_name|
+ step %(a git repo in "#{dir_name}")
+ step %(I cd to "#{dir_name}")
+end
+
+Given /^a git repo in "([^"]*)"$/ do |dir_name|
+ step %(a directory named "#{dir_name}")
+ dirs << dir_name
+ step %(I successfully run `git init --quiet`)
+ dirs.pop
+end
+
+Then /^"([^"]*)" should be run$/ do |cmd|
+ assert_command_run cmd
+end
+
+Then /^it should clone "([^"]*)"$/ do |repo|
+ step %("git clone #{repo}" should be run)
+end
+
+Then /^nothing should be run$/ do
+ history.should be_empty
+end
+
+Then /^there should be no output$/ do
+ assert_exact_output('', all_output)
+end
+
+Then /^the git command should be unchanged$/ do
+ @commands.should_not be_empty
+ assert_command_run @commands.last.sub(/^hub\b/, 'git')
+end
+
+Then /^the url for "([^"]*)" should be "([^"]*)"$/ do |name, url|
+ found = run_silent %(git config --get-all remote.#{name}.url)
+ found.should eql(url)
+end
+
+Then /^the "([^"]*)" submodule url should be "([^"]*)"$/ do |name, url|
+ found = run_silent %(git config --get-all submodule."#{name}".url)
+ found.should eql(url)
+end
View
21 features/submodule_add.feature
@@ -0,0 +1,21 @@
+Feature: hub submodule add
+ Background:
+ Given I am in "dotfiles" git repo
+ # make existing repo in subdirectory so git clone isn't triggered
+ Given a git repo in "vendor/grit"
+
+ Scenario: Add public submodule
+ When I successfully run `hub submodule add mojombo/grit vendor/grit`
+ Then the "vendor/grit" submodule url should be "git://github.com/mojombo/grit.git"
+ And the output should contain exactly:
+ """
+ Adding existing repo at 'vendor/grit' to the index\n
+ """
+
+ Scenario: Add private submodule
+ When I successfully run `hub submodule add -p mojombo/grit vendor/grit`
+ Then the "vendor/grit" submodule url should be "git@github.com:mojombo/grit.git"
+
+ Scenario: Add submodule with arguments
+ When I successfully run `hub submodule add -b foo mojombo/grit vendor/grit`
+ Then "git submodule add -b foo git://github.com/mojombo/grit.git vendor/grit" should be run
View
272 test/hub_test.rb
@@ -82,278 +82,6 @@ def setup
'rev-parse -q --git-dir' => '.git'
end
- def test_private_clone
- stub_no_git_repo
- input = "clone -p rtomayko/ronn"
- command = "git clone git@github.com:rtomayko/ronn.git"
- assert_command input, command
- end
-
- def test_private_clone_noop
- stub_no_git_repo
- input = "--noop clone -p rtomayko/ronn"
- command = "git clone git@github.com:rtomayko/ronn.git\n"
- assert_output command, hub(input)
- end
-
- def test_https_clone
- stub_no_git_repo
- stub_https_is_preferred
- input = "clone rtomayko/ronn"
- command = "git clone https://github.com/rtomayko/ronn.git"
- assert_command input, command
- end
-
- def test_public_clone
- stub_no_git_repo
- input = "clone rtomayko/ronn"
- command = "git clone git://github.com/rtomayko/ronn.git"
- assert_command input, command
- end
-
- def test_your_private_clone
- stub_no_git_repo
- input = "clone -p resque"
- command = "git clone git@github.com:tpw/resque.git"
- assert_command input, command
- end
-
- def test_your_clone_is_always_private
- stub_no_git_repo
- input = "clone resque"
- command = "git clone git@github.com:tpw/resque.git"
- assert_command input, command
- end
-
- def test_clone_repo_with_period
- stub_no_git_repo
- input = "clone hookio/hook.js"
- command = "git clone git://github.com/hookio/hook.js.git"
- assert_command input, command
- end
-
- def test_clone_with_arguments
- stub_no_git_repo
- input = "clone --bare -o master resque"
- command = "git clone --bare -o master git@github.com:tpw/resque.git"
- assert_command input, command
- end
-
- def test_clone_with_arguments_and_destination
- stub_no_git_repo
- assert_forwarded "clone --template=one/two git://github.com/tpw/resque.git --origin master resquetastic"
- end
-
- def xtest_your_private_clone_fails_without_config
- stub_no_git_repo
- out = hub("clone -p mustache") do
- stub_github_user(nil)
- end
-
- assert_equal "** No GitHub user set. See http://help.github.com/set-your-user-name-email-and-github-token/\n", out
- end
-
- def xtest_your_public_clone_fails_without_config
- stub_no_git_repo
- out = hub("clone mustache") do
- stub_github_user(nil)
- end
-
- assert_equal "** No GitHub user set. See http://help.github.com/set-your-user-name-email-and-github-token/\n", out
- end
-
- def test_private_clone_left_alone
- stub_no_git_repo
- assert_forwarded "clone git@github.com:rtomayko/ronn.git"
- end
-
- def test_public_clone_left_alone
- stub_no_git_repo
- assert_forwarded "clone git://github.com/rtomayko/ronn.git"
- end
-
- def test_normal_public_clone_with_path
- stub_no_git_repo
- assert_forwarded "clone git://github.com/rtomayko/ronn.git ronn-dev"
- end
-
- def test_normal_clone_from_path
- stub_no_git_repo
- assert_forwarded "clone ./test"
- end
-
- def test_unchanged_clone_from_existing_directory
- stub_no_git_repo
- assert_forwarded "clone test"
- end
-
- def test_local_clone_with_destination
- stub_no_git_repo
- assert_forwarded "clone -l . ../copy"
- end
-
- def test_clone_with_host_alias
- stub_no_git_repo
- assert_forwarded "clone server:git/repo.git"
- end
-
- def test_enterprise_clone
- stub_no_git_repo
- stub_github_user('myfiname', 'git.my.org')
- with_host_env('git.my.org') do
- assert_command "clone myrepo", "git clone git@git.my.org:myfiname/myrepo.git"
- assert_command "clone another/repo", "git clone git@git.my.org:another/repo.git"
- end
- end
-
- def test_alias_expand
- stub_alias 'c', 'clone --bare'
- input = "c rtomayko/ronn"
- command = "git clone --bare git://github.com/rtomayko/ronn.git"
- assert_command input, command
- end
-
- def test_alias_expand_advanced
- stub_alias 'c', 'clone --template="white space"'
- input = "c rtomayko/ronn"
- command = "git clone '--template=white space' git://github.com/rtomayko/ronn.git"
- assert_command input, command
- end
-
- def test_alias_doesnt_expand_for_unknown_commands
- stub_alias 'c', 'compute --fast'
- assert_forwarded "c rtomayko/ronn"
- end
-
- def test_remote_origin
- input = "remote add origin"
- command = "git remote add origin git://github.com/tpw/hub.git"
- assert_command input, command
- end
-
- def test_remote_add_with_name
- input = "remote add another hookio/hub.js"
- command = "git remote add another git://github.com/hookio/hub.js.git"
- assert_command input, command
- end
-
- def test_private_remote_origin
- input = "remote add -p origin"
- command = "git remote add origin git@github.com:tpw/hub.git"
- assert_command input, command
- end
-
- def test_public_remote_url_untouched
- assert_forwarded "remote add origin http://github.com/defunkt/resque.git"
- end
-
- def test_private_remote_url_untouched
- assert_forwarded "remote add origin git@github.com:defunkt/resque.git"
- end
-
- def test_remote_from_rel_path
- assert_forwarded "remote add origin ./path"
- end
-
- def test_remote_from_abs_path
- assert_forwarded "remote add origin /path"
- end
-
- def test_remote_with_host_alias
- assert_forwarded "remote add origin server:/git/repo.git"
- end
-
- def test_remote_add_enterprise
- stub_hub_host('git.my.org')
- stub_repo_url('git@git.my.org:defunkt/hub.git')
- assert_command "remote add another", "git remote add another git@git.my.org:another/hub.git"
- end
-
- def test_public_submodule
- input = "submodule add wycats/bundler vendor/bundler"
- command = "git submodule add git://github.com/wycats/bundler.git vendor/bundler"
- assert_command input, command
- end
-
- def test_private_submodule
- input = "submodule add -p grit vendor/grit"
- command = "git submodule add git@github.com:tpw/grit.git vendor/grit"
- assert_command input, command
- end
-
- def test_submodule_branch
- input = "submodule add -b ryppl ryppl/pip vendor/pip"
- command = "git submodule add -b ryppl git://github.com/ryppl/pip.git vendor/pip"
- assert_command input, command
- end
-
- def test_submodule_with_args
- input = "submodule -q add --bare -- grit grit"
- command = "git submodule -q add --bare -- git://github.com/tpw/grit.git grit"
- assert_command input, command
- end
-
- def test_private_remote
- input = "remote add -p rtomayko"
- command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
- assert_command input, command
- end
-
- def test_https_protocol_remote
- stub_https_is_preferred
- input = "remote add rtomayko"
- command = "git remote add rtomayko https://github.com/rtomayko/hub.git"
- assert_command input, command
- end
-
- def test_public_remote
- input = "remote add rtomayko"
- command = "git remote add rtomayko git://github.com/rtomayko/hub.git"
- assert_command input, command
- end
-
- def test_public_remote_f
- input = "remote add -f rtomayko"
- command = "git remote add -f rtomayko git://github.com/rtomayko/hub.git"
- assert_command input, command
- end
-
- def test_named_public_remote
- input = "remote add origin rtomayko"
- command = "git remote add origin git://github.com/rtomayko/hub.git"
- assert_command input, command
- end
-
- def test_named_public_remote_f
- input = "remote add -f origin rtomayko"
- command = "git remote add -f origin git://github.com/rtomayko/hub.git"
- assert_command input, command
- end
-
- def test_private_remote_with_repo
- input = "remote add -p jashkenas/coffee-script"
- command = "git remote add jashkenas git@github.com:jashkenas/coffee-script.git"
- assert_command input, command
- end
-
- def test_public_remote_with_repo
- input = "remote add jashkenas/coffee-script"
- command = "git remote add jashkenas git://github.com/jashkenas/coffee-script.git"
- assert_command input, command
- end
-
- def test_public_remote_f_with_repo
- input = "remote add -f jashkenas/coffee-script"
- command = "git remote add -f jashkenas git://github.com/jashkenas/coffee-script.git"
- assert_command input, command
- end
-
- def test_named_private_remote_with_repo
- input = "remote add -p origin jashkenas/coffee-script"
- command = "git remote add origin git@github.com:jashkenas/coffee-script.git"
- assert_command input, command
- end
-
def test_fetch_existing_remote
assert_forwarded "fetch mislav"
end

0 comments on commit 501e20b

Please sign in to comment.