From 2200d937889877ed1915872e08dc388fcf03a27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 27 Jul 2014 12:11:25 -0700 Subject: [PATCH] Port remaining `pull-request` tests to cukes --- features/pull_request.feature | 34 +++++++++++++++++++++++++++++++++- features/steps.rb | 8 ++++++-- test/hub_test.rb | 32 -------------------------------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/features/pull_request.feature b/features/pull_request.feature index 22abf692..39f7a815 100644 --- a/features/pull_request.feature +++ b/features/pull_request.feature @@ -465,7 +465,25 @@ Feature: hub pull-request And "git.my.org" is a whitelisted Enterprise host Given the GitHub API server: """ - post('/api/v3/repos/mislav/coral/pulls') { + post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') { + assert :base => 'master', + :head => 'mislav:master' + json :html_url => "the://url" + } + """ + When I successfully run `hub pull-request -m enterprisey` + Then the output should contain exactly "the://url\n" + + Scenario: Enterprise remote witch matching branch but no tracking + Given the "origin" remote has url "git@git.my.org:mislav/coral.git" + And I am "mislav" on git.my.org with OAuth token "FITOKEN" + And "git.my.org" is a whitelisted Enterprise host + And I am on the "feature" branch pushed to "origin/feature" + Given the GitHub API server: + """ + post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') { + assert :base => 'master', + :head => 'mislav:feature' json :html_url => "the://url" } """ @@ -528,3 +546,17 @@ Feature: hub pull-request """ When I successfully run `hub pull-request -o -m hereyougo` Then "open the://url" should be run + + Scenario: Current branch is tracking local branch + Given git "push.default" is set to "upstream" + And I am on the "feature" branch with upstream "refs/heads/master" + Given the GitHub API server: + """ + post('/repos/mislav/coral/pulls') { + assert :base => 'master', + :head => 'mislav:feature' + json :html_url => "the://url" + } + """ + When I successfully run `hub pull-request -m hereyougo` + Then the output should contain exactly "the://url\n" diff --git a/features/steps.rb b/features/steps.rb index 46a46d0a..b3cf3efe 100644 --- a/features/steps.rb +++ b/features/steps.rb @@ -85,11 +85,15 @@ end Given(/^I am on the "([^"]+)" branch(?: (pushed to|with upstream) "([^"]+)")?$/) do |name, type, upstream| empty_commit if upstream - full_upstream = ".git/refs/remotes/#{upstream}" + if upstream =~ /^refs\// + full_upstream = ".git/#{upstream}" + else + full_upstream = ".git/refs/remotes/#{upstream}" + end in_current_dir do FileUtils.mkdir_p File.dirname(full_upstream) FileUtils.cp '.git/refs/heads/master', full_upstream - end + end unless upstream == 'refs/heads/master' end track = type == 'pushed to' ? '--no-track' : '--track' run_silent %(git checkout --quiet -B #{name} #{track} #{upstream}) diff --git a/test/hub_test.rb b/test/hub_test.rb index dbb5faea..ccf77f9a 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -161,38 +161,6 @@ class HubTest < Minitest::Test "cherry-pick xoebus@a319d88" end - def test_pullrequest_from_branch_tracking_local - stub_config_value 'push.default', 'upstream' - stub_branch('refs/heads/feature') - stub_tracking('feature', 'refs/heads/master') - - stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls"). - with(:body => {'base' => "master", 'head' => "defunkt:feature", 'title' => "hereyougo" }). - to_return(:body => mock_pullreq_response(1)) - - expected = "https://github.com/defunkt/hub/pull/1\n" - assert_output expected, "pull-request -m hereyougo -f" - end - - def test_pullrequest_enterprise_no_tracking - stub_hub_host('git.my.org') - stub_repo_url('git@git.my.org:defunkt/hub.git') - stub_branch('refs/heads/feature') - stub_remote_branch('origin/feature') - stub_tracking_nothing('feature') - stub_command_output "rev-list --cherry-pick --right-only --no-merges origin/feature...", nil - edit_hub_config do |data| - data['git.my.org'] = [{'user'=>'myfiname', 'oauth_token' => 'FITOKEN'}] - end - - stub_request(:post, "https://git.my.org/api/v3/repos/defunkt/hub/pulls"). - with(:body => {'base' => "master", 'head' => "defunkt:feature", 'title' => "hereyougo" }). - to_return(:body => mock_pullreq_response(1, 'api/v3/defunkt/hub', 'git.my.org')) - - expected = "https://git.my.org/api/v3/defunkt/hub/pull/1\n" - assert_output expected, "pull-request -m hereyougo -f" - end - def test_pullrequest_alias out = hub('e-note') assert_equal hub('pull-request'), out -- GitLab