From db7693691a189cf6fd69fd763c4ecd470d5213a8 Mon Sep 17 00:00:00 2001 From: Jian Li Date: Fri, 16 Nov 2012 21:53:40 -0800 Subject: [PATCH] add tests for `pull-request -l` --- test/hub_test.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/hub_test.rb b/test/hub_test.rb index 747af6ebe..51460e8c4 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -387,6 +387,30 @@ def test_pullrequest_existing_issue assert_output expected, "pull-request -i 92" end + def test_get_pullrequest + stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls?page=1&state=open"). + to_return(:body => + mock_list_pulls_response({ + 'defunkt:feature-foo' => 1, + 'defunkt:feature-bar' => 2, + })) + stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls?page=2&state=open"). + to_return(:body => + mock_list_pulls_response({ + 'jianlius:feature-baz' => 3, + 'jianlius:feature-qux' => 4, + })) + + expected = "https://github.com/defunkt/hub/pull/2\n" + assert_output expected, "pull-request -l feature-bar" + + stub_branch('refs/heads/feature-qux') + stub_tracking('feature-qux', 'upstream') + + expected = "https://github.com/defunkt/hub/pull/4\n" + assert_output expected, "pull-request -l" + end + def test_pullrequest_existing_issue_url stub_branch('refs/heads/myfix') stub_tracking('myfix', 'mislav', 'awesomefix') @@ -752,6 +776,19 @@ def mock_pull_response(label, priv = false) } end + def mock_list_pulls_response(branches, name_with_owner = 'defunkt/hub', host = 'github.com') + arr = [] + branches.each_pair do |branch, id| + arr << { + 'head' => { + 'label' => branch, + }, + 'html_url' => "https://#{host}/#{name_with_owner}/pull/#{id}", + } + end + Hub::JSON.generate arr + end + def improved_help_text Hub::Commands.send :improved_help_text end