github_api 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. data/README.md +50 -5
  2. data/features/cassettes/git_data/commits/get.yml +69 -0
  3. data/features/git_data/commmits.feature +14 -0
  4. data/lib/github_api.rb +1 -0
  5. data/lib/github_api/activity/events.rb +42 -33
  6. data/lib/github_api/activity/notifications.rb +22 -22
  7. data/lib/github_api/activity/starring.rb +16 -21
  8. data/lib/github_api/activity/watching.rb +16 -19
  9. data/lib/github_api/api.rb +51 -8
  10. data/lib/github_api/arguments.rb +155 -0
  11. data/lib/github_api/authorizations.rb +19 -20
  12. data/lib/github_api/configuration.rb +5 -0
  13. data/lib/github_api/emojis.rb +3 -3
  14. data/lib/github_api/error/validations.rb +2 -2
  15. data/lib/github_api/gists.rb +32 -42
  16. data/lib/github_api/gists/comments.rb +21 -23
  17. data/lib/github_api/git_data/blobs.rb +13 -16
  18. data/lib/github_api/git_data/commits.rb +12 -10
  19. data/lib/github_api/git_data/references.rb +24 -28
  20. data/lib/github_api/git_data/tags.rb +9 -11
  21. data/lib/github_api/git_data/trees.rb +10 -13
  22. data/lib/github_api/gitignore.rb +4 -6
  23. data/lib/github_api/issues.rb +24 -32
  24. data/lib/github_api/issues/assignees.rb +11 -8
  25. data/lib/github_api/issues/comments.rb +21 -26
  26. data/lib/github_api/issues/events.rb +7 -9
  27. data/lib/github_api/issues/labels.rb +39 -53
  28. data/lib/github_api/issues/milestones.rb +26 -33
  29. data/lib/github_api/markdown.rb +5 -6
  30. data/lib/github_api/meta.rb +3 -3
  31. data/lib/github_api/orgs.rb +10 -11
  32. data/lib/github_api/orgs/members.rb +18 -20
  33. data/lib/github_api/orgs/teams.rb +54 -58
  34. data/lib/github_api/pull_requests.rb +40 -54
  35. data/lib/github_api/pull_requests/comments.rb +19 -26
  36. data/lib/github_api/repos.rb +146 -101
  37. data/lib/github_api/repos/collaborators.rb +29 -30
  38. data/lib/github_api/repos/comments.rb +20 -25
  39. data/lib/github_api/repos/commits.rb +12 -14
  40. data/lib/github_api/repos/contents.rb +22 -14
  41. data/lib/github_api/repos/downloads.rb +19 -23
  42. data/lib/github_api/repos/forks.rb +6 -11
  43. data/lib/github_api/repos/hooks.rb +25 -34
  44. data/lib/github_api/repos/keys.rb +25 -27
  45. data/lib/github_api/repos/merging.rb +7 -6
  46. data/lib/github_api/repos/pub_sub_hubbub.rb +14 -18
  47. data/lib/github_api/repos/statuses.rb +13 -14
  48. data/lib/github_api/say.rb +1 -3
  49. data/lib/github_api/search.rb +12 -21
  50. data/lib/github_api/users.rb +10 -9
  51. data/lib/github_api/users/emails.rb +11 -9
  52. data/lib/github_api/users/followers.rb +25 -23
  53. data/lib/github_api/users/keys.rb +27 -29
  54. data/lib/github_api/version.rb +1 -1
  55. data/spec/github/activity/events/org_spec.rb +6 -6
  56. data/spec/github/activity/events/performed_spec.rb +1 -1
  57. data/spec/github/activity/events/received_spec.rb +1 -1
  58. data/spec/github/activity/events/user_org_spec.rb +4 -2
  59. data/spec/github/activity/notifications/create_spec.rb +1 -1
  60. data/spec/github/activity/notifications/delete_spec.rb +1 -1
  61. data/spec/github/activity/notifications/get_spec.rb +1 -1
  62. data/spec/github/activity/notifications/subscribed_spec.rb +1 -1
  63. data/spec/github/activity/starring/list_spec.rb +2 -0
  64. data/spec/github/activity/starring/starring_spec.rb +1 -1
  65. data/spec/github/activity/watching/list_spec.rb +2 -0
  66. data/spec/github/activity/watching/watching_spec.rb +1 -3
  67. data/spec/github/api/set_spec.rb +18 -4
  68. data/spec/github/api/with_spec.rb +28 -0
  69. data/spec/github/api_spec.rb +11 -33
  70. data/spec/github/arguments/parse_spec.rb +68 -0
  71. data/spec/github/authorizations/delete_spec.rb +1 -1
  72. data/spec/github/authorizations/get_spec.rb +1 -1
  73. data/spec/github/error/validations_spec.rb +3 -3
  74. data/spec/github/gists/comments/list_spec.rb +1 -1
  75. data/spec/github/gists/delete_spec.rb +1 -1
  76. data/spec/github/gists/fork_spec.rb +1 -1
  77. data/spec/github/gists/get_spec.rb +1 -1
  78. data/spec/github/gists/is_starred_spec.rb +2 -0
  79. data/spec/github/gists/star_spec.rb +1 -1
  80. data/spec/github/gists/unstar_spec.rb +1 -1
  81. data/spec/github/git_data/blobs/create_spec.rb +2 -0
  82. data/spec/github/git_data/blobs/get_spec.rb +1 -1
  83. data/spec/github/git_data/commits/create_spec.rb +2 -0
  84. data/spec/github/git_data/commits/get_spec.rb +3 -3
  85. data/spec/github/git_data/references/create_spec.rb +1 -1
  86. data/spec/github/git_data/references/delete_spec.rb +3 -1
  87. data/spec/github/git_data/tags/create_spec.rb +2 -0
  88. data/spec/github/gitignore/get_spec.rb +1 -1
  89. data/spec/github/issues/events/get_spec.rb +3 -1
  90. data/spec/github/issues/events/list_spec.rb +3 -1
  91. data/spec/github/issues/labels/add_spec.rb +6 -6
  92. data/spec/github/issues/labels/list_spec.rb +3 -1
  93. data/spec/github/issues/labels/replace_spec.rb +6 -7
  94. data/spec/github/issues/milestones/get_spec.rb +2 -0
  95. data/spec/github/normalizer_spec.rb +18 -6
  96. data/spec/github/orgs/members/conceal_spec.rb +6 -4
  97. data/spec/github/orgs/members/delete_spec.rb +2 -0
  98. data/spec/github/orgs/members/list_spec.rb +1 -1
  99. data/spec/github/orgs/members/member_spec.rb +3 -1
  100. data/spec/github/orgs/members/publicize_spec.rb +2 -0
  101. data/spec/github/orgs/teams/add_member_spec.rb +2 -0
  102. data/spec/github/orgs/teams/create_spec.rb +1 -1
  103. data/spec/github/orgs/teams/delete_spec.rb +1 -1
  104. data/spec/github/orgs/teams/edit_spec.rb +1 -1
  105. data/spec/github/orgs/teams/get_spec.rb +1 -1
  106. data/spec/github/orgs/teams/list_spec.rb +1 -1
  107. data/spec/github/orgs/teams/team_member_spec.rb +3 -1
  108. data/spec/github/parameter_filter_spec.rb +19 -58
  109. data/spec/github/pull_requests/comments/create_spec.rb +3 -1
  110. data/spec/github/pull_requests/comments/delete_spec.rb +1 -1
  111. data/spec/github/pull_requests/comments/edit_spec.rb +2 -0
  112. data/spec/github/pull_requests/comments/get_spec.rb +3 -1
  113. data/spec/github/pull_requests/comments/list_spec.rb +3 -1
  114. data/spec/github/pull_requests/commits_spec.rb +3 -3
  115. data/spec/github/pull_requests/create_spec.rb +4 -0
  116. data/spec/github/pull_requests/files_spec.rb +4 -0
  117. data/spec/github/pull_requests/get_spec.rb +3 -3
  118. data/spec/github/pull_requests/list_spec.rb +3 -3
  119. data/spec/github/pull_requests/merge_spec.rb +2 -0
  120. data/spec/github/pull_requests/merged_spec.rb +3 -1
  121. data/spec/github/pull_requests/update_spec.rb +4 -0
  122. data/spec/github/repos/collaborators/add_spec.rb +3 -1
  123. data/spec/github/repos/collaborators/get_spec.rb +1 -3
  124. data/spec/github/repos/collaborators/list_spec.rb +5 -1
  125. data/spec/github/repos/collaborators/remove_spec.rb +3 -1
  126. data/spec/github/repos/comments/create_spec.rb +4 -0
  127. data/spec/github/repos/comments/delete_spec.rb +2 -2
  128. data/spec/github/repos/comments/get_spec.rb +6 -2
  129. data/spec/github/repos/commits/compare_spec.rb +3 -3
  130. data/spec/github/repos/commits/get_spec.rb +3 -3
  131. data/spec/github/repos/commits/list_spec.rb +3 -3
  132. data/spec/github/repos/contents/archive_spec.rb +12 -0
  133. data/spec/github/repos/contents/get_spec.rb +5 -0
  134. data/spec/github/repos/contributors_spec.rb +7 -2
  135. data/spec/github/repos/downloads/create_spec.rb +4 -0
  136. data/spec/github/repos/downloads/delete_spec.rb +5 -1
  137. data/spec/github/repos/downloads/get_spec.rb +3 -1
  138. data/spec/github/repos/downloads/list_spec.rb +3 -1
  139. data/spec/github/repos/forks/create_spec.rb +2 -0
  140. data/spec/github/repos/forks/list_spec.rb +3 -1
  141. data/spec/github/repos/hooks/edit_spec.rb +1 -1
  142. data/spec/github/repos/keys/delete_spec.rb +1 -1
  143. data/spec/github/repos/keys/edit_spec.rb +2 -0
  144. data/spec/github/repos/keys/get_spec.rb +3 -1
  145. data/spec/github/repos/keys/list_spec.rb +4 -2
  146. data/spec/github/repos/list_spec.rb +6 -1
  147. data/spec/github/repos/pub_sub_hubbub/subscribe_service_spec.rb +27 -0
  148. data/spec/github/repos/pub_sub_hubbub/subscribe_spec.rb +51 -0
  149. data/spec/github/repos/pub_sub_hubbub/unsubscribe_service_spec.rb +21 -0
  150. data/spec/github/repos/pub_sub_hubbub/unsubscribe_spec.rb +58 -0
  151. data/spec/github/repos/statuses/create_spec.rb +2 -0
  152. data/spec/github/search_spec.rb +25 -10
  153. data/spec/github/users/followers/follow_spec.rb +1 -1
  154. data/spec/github/users/followers/is_following_spec.rb +1 -1
  155. data/spec/github/users/followers/unfollow_spec.rb +1 -1
  156. data/spec/github/users/keys/delete_spec.rb +1 -1
  157. data/spec/github/users/keys/get_spec.rb +1 -1
  158. data/spec/github/users/keys/update_spec.rb +1 -1
  159. data/spec/github/users/update_spec.rb +1 -1
  160. data/spec/integration/arguments_spec.rb +76 -0
  161. data/spec/{github → integration}/authorizations_spec.rb +0 -0
  162. metadata +44 -35
  163. data/spec/github/repos/pub_sub_hubbub_spec.rb +0 -78
@@ -8,13 +8,13 @@ module Github
8
8
  # List public keys for the authenticated user
9
9
  #
10
10
  # = Examples
11
- # github = Github.new :oauth_token => '...'
11
+ # github = Github.new oauth_token: '...'
12
12
  # github.users.keys.list
13
13
  # github.users.keys.list { |key| ... }
14
14
  #
15
- def list(params={})
16
- normalize! params
17
- response = get_request("/user/keys", params)
15
+ def list(*args)
16
+ arguments(args)
17
+ response = get_request("/user/keys", arguments.params)
18
18
  return response unless block_given?
19
19
  response.each { |el| yield el }
20
20
  end
@@ -23,13 +23,12 @@ module Github
23
23
  # Get a single pulic key for the authenticated user
24
24
  #
25
25
  # = Examples
26
- # github = Github.new :oauth_token => '...'
26
+ # github = Github.new oauth_token: '...'
27
27
  # github.users.keys.get 'key-id'
28
28
  #
29
- def get(key_id, params={})
30
- assert_presence_of key_id
31
- normalize! params
32
- get_request("/user/keys/#{key_id}", params)
29
+ def get(*args)
30
+ arguments(args, :required => [:key_id])
31
+ get_request("/user/keys/#{key_id}", arguments.params)
33
32
  end
34
33
  alias :find :get
35
34
 
@@ -40,14 +39,14 @@ module Github
40
39
  # * <tt>:key</tt> - Required string. sha key
41
40
  #
42
41
  # = Examples
43
- # github = Github.new :oauth_token => '...'
44
- # github.users.keys.create "title" => "octocat@octomac",
45
- # "key" => "ssh-rsa AAA..."
42
+ # github = Github.new oauth_token: '...'
43
+ # github.users.keys.create "title": "octocat@octomac", "key": "ssh-rsa AAA..."
46
44
  #
47
- def create(params={})
48
- normalize! params
49
- filter! VALID_KEY_PARAM_NAMES, params
50
- post_request("/user/keys", params)
45
+ def create(*args)
46
+ arguments(args) do
47
+ sift VALID_KEY_PARAM_NAMES
48
+ end
49
+ post_request("/user/keys", arguments.params)
51
50
  end
52
51
 
53
52
  # Update a public key for the authenticated user
@@ -57,27 +56,26 @@ module Github
57
56
  # * <tt>:key</tt> - Required string. sha key
58
57
  #
59
58
  # = Examples
60
- # github = Github.new :oauth_token => '...'
61
- # github.users.keys.update 'key-id', "title" => "octocat@octomac",
62
- # "key" => "ssh-rsa AAA..."
59
+ # github = Github.new oauth_token: '...'
60
+ # github.users.keys.update 'key-id', "title": "octocat@octomac",
61
+ # "key": "ssh-rsa AAA..."
63
62
  #
64
- def update(key_id, params={})
65
- assert_presence_of key_id
66
- normalize! params
67
- filter! VALID_KEY_PARAM_NAMES, params
68
- patch_request("/user/keys/#{key_id}", params)
63
+ def update(*args)
64
+ arguments(args, :required => [:key_id]) do
65
+ sift VALID_KEY_PARAM_NAMES
66
+ end
67
+ patch_request("/user/keys/#{key_id}", arguments.params)
69
68
  end
70
69
 
71
70
  # Delete a public key for the authenticated user
72
71
  #
73
72
  # = Examples
74
- # github = Github.new :oauth_token => '...'
73
+ # github = Github.new oauth_token: '...'
75
74
  # github.users.keys.delete 'key-id'
76
75
  #
77
- def delete(key_id, params={})
78
- assert_presence_of key_id
79
- normalize! params
80
- delete_request("/user/keys/#{key_id}", params)
76
+ def delete(*args)
77
+ arguments(args, :required => [:key_id])
78
+ delete_request("/user/keys/#{key_id}", arguments.params)
81
79
  end
82
80
 
83
81
  end # Users::Keys
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 9
7
- PATCH = 0
7
+ PATCH = 1
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Github::Activity::Events, '#org' do
5
+ describe Github::Activity::Events, '#organization' do
6
6
  let(:org) { 'github' }
7
7
  let(:request_path) { "/orgs/#{org}/events" }
8
8
  let(:body) { fixture('events/events.json') }
@@ -19,11 +19,11 @@ describe Github::Activity::Events, '#org' do
19
19
  it { should respond_to :organization }
20
20
 
21
21
  it "should fail to get resource without orgname" do
22
- expect { subject.org nil }.to raise_error(ArgumentError)
22
+ expect { subject.organization }.to raise_error(ArgumentError)
23
23
  end
24
24
 
25
25
  it "should get the resources" do
26
- subject.org org
26
+ subject.organization org
27
27
  a_get(request_path).should have_been_made
28
28
  end
29
29
 
@@ -32,19 +32,19 @@ describe Github::Activity::Events, '#org' do
32
32
  end
33
33
 
34
34
  it "should get event information" do
35
- events = subject.org org
35
+ events = subject.organization org
36
36
  events.first.type.should == 'Event'
37
37
  end
38
38
 
39
39
  it "should yield to a block" do
40
40
  yielded = []
41
- result = subject.org(org) { |obj| yielded << obj }
41
+ result = subject.organization(org) { |obj| yielded << obj }
42
42
  yielded.should == result
43
43
  end
44
44
  end
45
45
 
46
46
  it_should_behave_like 'request failure' do
47
- let(:requestable) { subject.org org }
47
+ let(:requestable) { subject.organization org }
48
48
  end
49
49
 
50
50
  end # org
@@ -18,7 +18,7 @@ describe Github::Activity::Events, '#performed' do
18
18
  context "resource found" do
19
19
 
20
20
  it "should fail to get resource without username" do
21
- expect { subject.performed nil }.to raise_error(ArgumentError)
21
+ expect { subject.performed }.to raise_error(ArgumentError)
22
22
  end
23
23
 
24
24
  it "should get the resources" do
@@ -18,7 +18,7 @@ describe Github::Activity::Events, '#received' do
18
18
  context "resource found" do
19
19
 
20
20
  it "should fail to get resource without username" do
21
- expect { subject.received nil }.to raise_error(ArgumentError)
21
+ expect { subject.received }.to raise_error(ArgumentError)
22
22
  end
23
23
 
24
24
  it "should get the resources" do
@@ -19,8 +19,10 @@ describe Github::Activity::Events, '#user_org' do
19
19
  context "resource found" do
20
20
  it { should respond_to :user_organization }
21
21
 
22
+ it { expect { subject.user_org }.to raise_error(ArgumentError) }
23
+
22
24
  it "should fail to get resource without orgname" do
23
- expect { subject.user_org user, nil }.to raise_error(ArgumentError)
25
+ expect { subject.user_org user }.to raise_error(ArgumentError)
24
26
  end
25
27
 
26
28
  it "should get the resources" do
@@ -45,7 +47,7 @@ describe Github::Activity::Events, '#user_org' do
45
47
  end
46
48
 
47
49
  it_should_behave_like 'request failure' do
48
- let(:requestable) { subject.user_org user, org }
50
+ let(:requestable) { subject.user_org(user, org) }
49
51
  end
50
52
 
51
53
  end # user_org
@@ -26,7 +26,7 @@ describe Github::Activity::Notifications, '#create' do
26
26
  let(:status) { 200 }
27
27
 
28
28
  it 'asserts thread id presence' do
29
- expect { subject.create nil }.to raise_error(ArgumentError)
29
+ expect { subject.create }.to raise_error(ArgumentError)
30
30
  end
31
31
 
32
32
  it 'should create resource' do
@@ -26,7 +26,7 @@ describe Github::Activity::Notifications, '#delete' do
26
26
  end
27
27
 
28
28
  it "should fail to delete resource without 'user' parameter" do
29
- expect { subject.delete nil }.to raise_error(ArgumentError)
29
+ expect { subject.delete }.to raise_error(ArgumentError)
30
30
  end
31
31
 
32
32
  context 'failed to delete' do
@@ -20,7 +20,7 @@ describe Github::Activity::Notifications, '#get' do
20
20
  it { should respond_to(:find) }
21
21
 
22
22
  it "should raise error when no thread-id parameter" do
23
- expect { subject.get nil }.to raise_error(ArgumentError)
23
+ expect { subject.get }.to raise_error(ArgumentError)
24
24
  end
25
25
 
26
26
  it "should find resources" do
@@ -20,7 +20,7 @@ describe Github::Activity::Notifications, '#subscribed?' do
20
20
  let(:status) { 200 }
21
21
 
22
22
  it 'asserts thread id presence' do
23
- expect { subject.subscribed? nil }.to raise_error(ArgumentError)
23
+ expect { subject.subscribed? }.to raise_error(ArgumentError)
24
24
  end
25
25
 
26
26
  it 'gets the resource' do
@@ -20,6 +20,8 @@ describe Github::Activity::Starring, '#list' do
20
20
 
21
21
  it { should respond_to :all }
22
22
 
23
+ it { expect { subject.list user }.to raise_error(ArgumentError) }
24
+
23
25
  it "should fail to get resource without username" do
24
26
  expect { subject.list }.to raise_error(ArgumentError)
25
27
  end
@@ -32,7 +32,7 @@ describe Github::Activity::Starring, '#list' do
32
32
 
33
33
  context "without username and reponame passed" do
34
34
  it "should fail validation " do
35
- expect { subject.starring? nil, nil }.to raise_error(ArgumentError)
35
+ expect { subject.starring? user }.to raise_error(ArgumentError)
36
36
  end
37
37
  end
38
38
  end # starring?
@@ -16,6 +16,8 @@ describe Github::Activity::Watching, '#list' do
16
16
  to_return(:body => body, :status => status, :headers => {})
17
17
  }
18
18
 
19
+ it { expect { subject.list user }.to raise_error(ArgumentError) }
20
+
19
21
  it "should fail to get resource without username" do
20
22
  expect { subject.list }.to raise_error(ArgumentError)
21
23
  end
@@ -33,9 +33,7 @@ describe Github::Activity::Watching, '#list' do
33
33
 
34
34
  context "without username and reponame passed" do
35
35
  it "should fail validation " do
36
- expect {
37
- subject.watching?(nil, nil)
38
- }.to raise_error(ArgumentError)
36
+ expect { subject.watching? user, nil }.to raise_error(ArgumentError)
39
37
  end
40
38
  end
41
39
  end # watching?
@@ -10,10 +10,24 @@ describe Github::API, '#set' do
10
10
  expect { subject.set :option }.to raise_error(ArgumentError)
11
11
  end
12
12
 
13
- it 'accepts more than one option' do
14
- subject.set :user => 'user-name', :repo => 'repo-name'
15
- subject.user.should == 'user-name'
16
- subject.repo.should == 'repo-name'
13
+ context 'accpets more than one option' do
14
+ before { subject.set :user => 'user-name', :repo => 'repo-name' }
15
+
16
+ it 'sets user' do
17
+ subject.user.should == 'user-name'
18
+ end
19
+
20
+ it 'sets repo' do
21
+ subject.repo.should == 'repo-name'
22
+ end
23
+ end
24
+
25
+ context 'defines accessors' do
26
+ before { subject.set :branch, 'arguments' }
27
+
28
+ it { should respond_to :branch }
29
+
30
+ it { should respond_to 'branch=' }
17
31
  end
18
32
 
19
33
  end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::API, '#with' do
6
+ let(:user) { 'peter-murach' }
7
+
8
+ after { reset_authentication_for subject }
9
+
10
+ context 'with hash' do
11
+ it 'supports list of options' do
12
+ subject.with(:user => user, :repo => 'github')
13
+ subject.user.should == user
14
+ end
15
+ end
16
+
17
+ context 'with string' do
18
+ it 'support forward slash delimiter options' do
19
+ subject.with('peter-murach/github')
20
+ subject.user.should == user
21
+ end
22
+
23
+ it 'fails without slash delimiter' do
24
+ expect { subject.with('peter-murach') }.to raise_error(ArgumentError)
25
+ end
26
+ end
27
+
28
+ end
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::API do
4
- let(:api) { Github::API.new }
5
- let(:repos) { Github::Repos }
4
+ subject { described_class.new(options) }
6
5
 
7
6
  it { described_class.included_modules.should include Github::Authorization }
8
7
  it { described_class.included_modules.should include Github::MimeType }
@@ -10,7 +9,10 @@ describe Github::API do
10
9
  it { described_class.included_modules.should include Github::Request }
11
10
 
12
11
  context 'actions' do
13
- it { described_class.new.should respond_to :api_methods_in }
12
+ let(:options) { { } }
13
+ let(:repos) { Github::Repos }
14
+
15
+ it { should respond_to :api_methods_in }
14
16
 
15
17
  it 'dynamically adds actions inspection to classes inheriting from api' do
16
18
  repos.should respond_to :actions
@@ -21,44 +23,20 @@ describe Github::API do
21
23
  methods = [ 'method_a', 'method_b']
22
24
  repos.stub(:instance_methods).and_return methods
23
25
  output = capture(:stdout) {
24
- api.api_methods_in(repos)
26
+ subject.api_methods_in(repos)
25
27
  }
26
28
  output.should =~ /.*method_a.*/
27
29
  output.should =~ /.*method_b.*/
28
30
  end
29
31
  end
30
32
 
31
- context '_process_basic_auth' do
32
- let(:github) { Github.new :basic_auth => 'login:password' }
33
-
34
- after { reset_authentication_for github }
35
-
36
- it 'should parse authentication params' do
37
- github.login.should eq 'login'
38
- github.password.should eq 'password'
39
- end
40
- end
33
+ context 'process_basic_auth' do
34
+ let(:options) { { :basic_auth => 'login:password' } }
41
35
 
42
- context 'normalize!' do
43
- before do
44
- @params = { 'a' => { :b => { 'c' => 1 }, 'd' => [ 'a', { :e => 2 }] } }
45
- end
36
+ its(:login) { should eq 'login' }
46
37
 
47
- it "should stringify all the keys inside nested hash" do
48
- actual = api.normalize! @params
49
- expected = { 'a' => { 'b'=> { 'c' => 1 }, 'd' => [ 'a', { 'e'=> 2 }] } }
50
- actual.should be_eql expected
51
- end
52
- end
38
+ its(:password) { should eq 'password' }
53
39
 
54
- context 'filter!' do
55
- it "should remove non valid param keys" do
56
- valid = ['a', 'b', 'e']
57
- hash = {'a' => 1, 'b' => 3, 'c' => 2, 'd'=> 4, 'e' => 5 }
58
- actual = api.filter! valid, hash
59
- expected = {'a' => 1, 'b' => 3, 'e' => 5 }
60
- actual.should be_eql expected
61
- end
40
+ its(:basic_auth) { should eq 'login:password' }
62
41
  end
63
-
64
42
  end # Github::API
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Arguments, '#parse' do
6
+ let(:api) { Github::Repos.new }
7
+ let(:object) { described_class.new api, 'required' => required }
8
+ let(:arguments) { ['peter-murach', 'github', params] }
9
+ let(:params) { { :page => 23 } }
10
+ let(:required) { [:user, :repo] }
11
+
12
+ subject { object.parse *arguments }
13
+
14
+ after { api.user =nil; api.repo = nil }
15
+
16
+ context 'with required arguments' do
17
+
18
+ it { should == object }
19
+
20
+ its(:params) { should == params }
21
+
22
+ context 'sets parameters' do
23
+ it { subject.api.user.should == 'peter-murach' }
24
+
25
+ it { subject.api.repo.should == 'github' }
26
+ end
27
+
28
+ context 'with no arguments search parameters hash' do
29
+ let(:arguments) { nil }
30
+
31
+ it 'asserts lack of presence of hash parameters' do
32
+ expect { subject }.to raise_error(ArgumentError)
33
+ end
34
+ end
35
+
36
+ context 'with nil argument' do
37
+ let(:arguments) { [nil, 'github', params] }
38
+
39
+ it 'raises an error' do
40
+ expect { subject }.to raise_error(ArgumentError, /parameter/)
41
+ end
42
+ end
43
+
44
+ context 'with hash arguments' do
45
+ let(:arguments) { [{:user => 'peter-murach', :repo => 'github'}.merge(params)]}
46
+
47
+ it 'sets parameters' do
48
+ subject.api.user.should == 'peter-murach'
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'with less than required arguments' do
54
+ let(:required) { [:user, :repo] }
55
+ let(:arguments) { ['peter-murach', params] }
56
+
57
+ it 'raises an error' do
58
+ expect { subject }.to raise_error(ArgumentError, /wrong number/)
59
+ end
60
+ end
61
+
62
+ context 'without required arguments' do
63
+ let(:required) { [] }
64
+ let(:arguments) { [params] }
65
+
66
+ its(:params) { should == params }
67
+ end
68
+ end