Permalink
Browse files

add tests for `pull-request -l`

  • Loading branch information...
1 parent 8ca76ff commit db7693691a189cf6fd69fd763c4ecd470d5213a8 @jianli committed Nov 17, 2012
Showing with 37 additions and 0 deletions.
  1. +37 −0 test/hub_test.rb
View
37 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

0 comments on commit db76936

Please sign in to comment.