github-v3-api 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f692dff20ddbd6902535cc3e21c21daad15011a7
4
- data.tar.gz: 94e3d1a031dd93bdfd43300a8e33bbf110a9da44
3
+ metadata.gz: ac5a14f8e48660b650280828fb50755370ed06ed
4
+ data.tar.gz: 2c36d07918f201c1af217d18960efd286a1d0237
5
5
  SHA512:
6
- metadata.gz: decad8e4794a5b87bf3f22b292226791bcd672df7f2f70326bd1fbd6bfa6f61eb2a8ce9d15510bc37eafe9f68dd3529657f96862a2e7492778109d6cf76a3564
7
- data.tar.gz: 6d45d0bcaa1e25d2fdbfb4dab2201ee80f35a209dc5f2d19b23bc74beb83910f5592f9b6eeeb7b6afe87beab724bac700e1df962ec11eef7450b39f9883f2dcf
6
+ metadata.gz: 790bb64597d4826870654f48a57246cb001be5040b8426a3c41cc2d6d7324fb45de09e55b8f3fc397b37797f9c3fb9ebb65fe93de15913c45a0e1f3043bf2b86
7
+ data.tar.gz: d1916ed66542c9029348558d6bdd232561368033f33a40f86a9c9a8b8387c3b432d8f2a6ecdb6f395a010ed550447f1f2157ed8c0fc2231af25a38b14e743a03
@@ -34,8 +34,13 @@ class GitHubV3API
34
34
  # +access_token+ owner's authorization.
35
35
  #
36
36
  # +access_token+:: an OAuth2 access token from GitHub
37
- def initialize(access_token)
37
+ def initialize(access_token, api_url='https://api.github.com', header={})
38
38
  @access_token = access_token
39
+ @api_url = api_url
40
+ @header = {:accept => :json,
41
+ :authorization => "token #{@access_token}",
42
+ :user_agent => "rubygem-github-v3-api"}
43
+ @header.merge!(header) if header.is_a?(Hash)
39
44
  end
40
45
 
41
46
  # Entry-point for access to the GitHub Users API
@@ -71,14 +76,13 @@ class GitHubV3API
71
76
  end
72
77
 
73
78
  def get(path, params={}) #:nodoc:
74
- result = RestClient.get("https://api.github.com" + path,
75
- {:accept => :json,
76
- :authorization => "token #{@access_token}"}.merge({:params => params}))
79
+ result = RestClient.get(@api_url + path,
80
+ @header.merge({:params => params}))
77
81
  result_data = JSON.parse(result)
78
82
  # check for pagination
79
83
  link = result.headers[:link]
80
84
  if link then
81
- re_relnext = /<https:\/\/api.github.com([^>]*)>; *rel="next"/
85
+ re_relnext = %r!<#{@api_url}([^>]*)>; *rel="next"!
82
86
  relnext_path = link.match re_relnext
83
87
  if relnext_path && relnext_path[1] then
84
88
  next_data = self.get(relnext_path[1], params)
@@ -91,27 +95,24 @@ class GitHubV3API
91
95
  end
92
96
 
93
97
  def post(path, params={}) #:nodoc:
94
- result = RestClient.post("https://api.github.com" + path, JSON.generate(params),
95
- {:accept => :json,
96
- :authorization => "token #{@access_token}"})
98
+ result = RestClient.post(@api_url + path, JSON.generate(params),
99
+ @header)
97
100
  JSON.parse(result)
98
101
  rescue RestClient::Unauthorized
99
102
  raise Unauthorized, "The access token is invalid according to GitHub"
100
103
  end
101
104
 
102
105
  def patch(path, params={}) #:nodoc:
103
- result = RestClient.post("https://api.github.com" + path, JSON.generate(params),
104
- {:accept => :json,
105
- :authorization => "token #{@access_token}"})
106
+ result = RestClient.post(@api_url + path, JSON.generate(params),
107
+ @header)
106
108
  JSON.parse(result)
107
109
  rescue RestClient::Unauthorized
108
110
  raise Unauthorized, "The access token is invalid according to GitHub"
109
111
  end
110
112
 
111
113
  def delete(path) #:nodoc:
112
- result = RestClient.delete("https://api.github.com" + path,
113
- {:accept => :json,
114
- :authorization => "token #{@access_token}"})
114
+ result = RestClient.delete(@api_url + path,
115
+ @header)
115
116
  JSON.parse(result)
116
117
  rescue RestClient::Unauthorized
117
118
  raise Unauthorized, "The access token is invalid according to GitHub"
@@ -24,6 +24,13 @@ class GitHubV3API
24
24
  @connection = connection
25
25
  end
26
26
 
27
+ def public_repos
28
+ @connection.get('/repositories').map do |repo_data|
29
+ GitHubV3API::Repo.new(self, repo_data)
30
+ end
31
+ end
32
+
33
+
27
34
  # Returns an array of GitHubV3API::Repo instances representing the
28
35
  # user's public and private repos
29
36
  def list
@@ -35,6 +35,12 @@ class GitHubV3API
35
35
  user_data = @connection.get("/users/#{username}")
36
36
  GitHubV3API::User.new_with_all_data(self, user_data)
37
37
  end
38
-
38
+
39
+ # Returns an array of all GitHubV3API::User instances in the server.
40
+ def all
41
+ @connection.get("/users").map do |user_data|
42
+ GitHubV3API::User.new_with_all_data(self, user_data)
43
+ end
44
+ end
39
45
  end
40
46
  end
@@ -1,3 +1,3 @@
1
1
  class GitHubV3API
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,27 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GitHubV3API do
4
+ let(:auth_token) { 'abcde' }
5
+ let(:test_header) { {:accept => :json,
6
+ :authorization => "token #{auth_token}",
7
+ :user_agent => 'rubygem-github-v3-api'} }
8
+
4
9
  it 'is initialized with an OAuth2 access token' do
5
- lambda { GitHubV3API.new('abcde') }.should_not raise_error
10
+ lambda { GitHubV3API.new(auth_token) }.should_not raise_error
6
11
  end
7
12
 
8
13
  describe '#orgs' do
9
14
  it 'returns an instance of GitHubV3API::OrgsAPI' do
10
- api = GitHubV3API.new('abcde')
15
+ api = GitHubV3API.new(auth_token)
11
16
  api.orgs.should be_kind_of GitHubV3API::OrgsAPI
12
17
  end
13
18
  end
14
19
 
15
20
  describe '#repos' do
16
21
  it 'returns an instance of GitHubV3API::ReposAPI' do
17
- api = GitHubV3API.new('abcde')
22
+ api = GitHubV3API.new(auth_token)
18
23
  api.repos.should be_kind_of GitHubV3API::ReposAPI
19
24
  end
20
25
  end
21
26
 
22
27
  describe "#issues" do
23
28
  it "returns an instance of GitHubV3API::IssuesAPI" do
24
- api = GitHubV3API.new('abcde')
29
+ api = GitHubV3API.new(auth_token)
25
30
  api.issues.should be_kind_of GitHubV3API::IssuesAPI
26
31
  end
27
32
  end
@@ -29,19 +34,19 @@ describe GitHubV3API do
29
34
  describe '#get' do
30
35
  it 'does a get request to the specified path at the GitHub API server and adds the access token' do
31
36
  rcs = String.new('[]')
32
- rcs.stub!(:headers).and_return({})
37
+ allow(rcs).to receive(:headers) { {} }
33
38
  RestClient.should_receive(:get) \
34
- .with('https://api.github.com/some/path', {:accept => :json, :authorization => 'token abcde', :params => {}}) \
39
+ .with('https://api.github.com/some/path', test_header.merge({:params => {}})) \
35
40
  .and_return(rcs)
36
- api = GitHubV3API.new('abcde')
41
+ api = GitHubV3API.new(auth_token)
37
42
  api.get('/some/path')
38
43
  end
39
44
 
40
45
  it 'returns the result of parsing the result body as JSON' do
41
46
  rcs = String.new('[{"foo": "bar"}]')
42
- rcs.stub!(:headers).and_return({})
43
- RestClient.stub!(:get => rcs)
44
- api = GitHubV3API.new('abcde')
47
+ allow(rcs).to receive(:headers) { {} }
48
+ allow(RestClient).to receive(:get) { rcs }
49
+ api = GitHubV3API.new(auth_token)
45
50
  api.get('/something').should == [{"foo" => "bar"}]
46
51
  end
47
52
 
@@ -49,23 +54,23 @@ describe GitHubV3API do
49
54
  headers_next = { :link => 'Link: <https://api.github.com/some/nextpath>; rel="next", <https://api.github.com/some/lastpath>; rel="last"' }
50
55
  headers_last = { :link => 'Link: <https://api.github.com/some/prevpath>; rel="previous", <https://api.github.com/some/lastpath>; rel="last"' }
51
56
  rcs_next = String.new('[]')
52
- rcs_next.stub!(:headers).and_return(headers_next)
57
+ allow(rcs_next).to receive(:headers) { headers_next }
53
58
  rcs_last = String.new('[]')
54
- rcs_last.stub!(:headers).and_return(headers_last)
59
+ allow(rcs_last).to receive(:headers) { headers_last }
55
60
 
56
61
  RestClient.should_receive(:get) \
57
- .with('https://api.github.com/some/path', {:accept => :json, :authorization => 'token abcde', :params => {}}) \
62
+ .with('https://api.github.com/some/path', test_header.merge({:params => {}})) \
58
63
  .and_return(rcs_next)
59
64
  RestClient.should_receive(:get) \
60
- .with('https://api.github.com/some/nextpath', {:accept => :json, :authorization => 'token abcde', :params => {}}) \
65
+ .with('https://api.github.com/some/nextpath', test_header.merge({:params => {}})) \
61
66
  .and_return(rcs_last)
62
- api = GitHubV3API.new('abcde')
67
+ api = GitHubV3API.new(auth_token)
63
68
  api.get('/some/path')
64
69
  end
65
70
 
66
71
  it 'raises GitHubV3API::Unauthorized instead of RestClient::Unauthorized' do
67
- RestClient.stub!(:get).and_raise(RestClient::Unauthorized)
68
- api = GitHubV3API.new('abcde')
72
+ allow(RestClient).to receive(:get) { raise(RestClient::Unauthorized) }
73
+ api = GitHubV3API.new(auth_token)
69
74
  lambda { api.get('/something') }.should raise_error(GitHubV3API::Unauthorized)
70
75
  end
71
76
  end
@@ -75,9 +80,9 @@ describe GitHubV3API do
75
80
  data = {:title => 'omgbbq'}
76
81
  json = JSON.generate(data)
77
82
  RestClient.should_receive(:post) \
78
- .with('https://api.github.com/some/path', json, {:accept => :json, :authorization => 'token abcde'}) \
83
+ .with('https://api.github.com/some/path', json, test_header) \
79
84
  .and_return('{}')
80
- api = GitHubV3API.new('abcde')
85
+ api = GitHubV3API.new(auth_token)
81
86
  api.post('/some/path', data)
82
87
  end
83
88
  end
@@ -87,9 +92,9 @@ describe GitHubV3API do
87
92
  data = {:title => 'omgbbq'}
88
93
  json = JSON.generate(data)
89
94
  RestClient.should_receive(:post) \
90
- .with('https://api.github.com/some/path', json, {:accept => :json, :authorization => 'token abcde'}) \
95
+ .with('https://api.github.com/some/path', json, test_header) \
91
96
  .and_return('{}')
92
- api = GitHubV3API.new('abcde')
97
+ api = GitHubV3API.new(auth_token)
93
98
  api.patch('/some/path', data)
94
99
  end
95
100
  end
@@ -97,9 +102,9 @@ describe GitHubV3API do
97
102
  describe "#delete" do
98
103
  it 'does a delete request to the specified path at the GitHub API server and adds the access token' do
99
104
  RestClient.should_receive(:delete) \
100
- .with('https://api.github.com/some/path', {:accept => :json, :authorization => 'token abcde'}) \
105
+ .with('https://api.github.com/some/path', test_header) \
101
106
  .and_return('{}')
102
- api = GitHubV3API.new('abcde')
107
+ api = GitHubV3API.new(auth_token)
103
108
  api.delete('/some/path')
104
109
  end
105
110
  end
@@ -6,7 +6,7 @@ describe GitHubV3API::Issue do
6
6
  fields = %w(url html_url number state title body user labels assignee
7
7
  milestone comments pull_request closed_at created_at updated_at)
8
8
  fields.each do |f|
9
- repo = GitHubV3API::Issue.new_with_all_data(stub('api'), {f.to_s => 'foo'})
9
+ repo = GitHubV3API::Issue.new_with_all_data(double('api'), {f.to_s => 'foo'})
10
10
  repo.methods.should include(f.to_sym)
11
11
  repo.send(f).should == 'foo'
12
12
  end
@@ -4,7 +4,7 @@ describe GitHubV3API::IssuesAPI do
4
4
  describe "#list" do
5
5
  context "options = nil" do
6
6
  it "returns issues for a user" do
7
- connection = mock(GitHubV3API)
7
+ connection = double(GitHubV3API)
8
8
  connection.should_receive(:get).with('/issues', {}).and_return([:issue_hash1, :issue_hash2])
9
9
  api = GitHubV3API::IssuesAPI.new(connection)
10
10
  GitHubV3API::Issue.should_receive(:new).with(api, :issue_hash1).and_return(:issue1)
@@ -16,7 +16,7 @@ describe GitHubV3API::IssuesAPI do
16
16
 
17
17
  context "options = {:user => 'octocat', :repo => 'hello-world'}" do
18
18
  it "returns issues for a repo" do
19
- connection = mock(GitHubV3API)
19
+ connection = double(GitHubV3API)
20
20
  connection.should_receive(:get).with("/repos/octocat/hello-world/issues", {}).and_return([:issue_hash1, :issue_hash2])
21
21
  api = GitHubV3API::IssuesAPI.new(connection)
22
22
  GitHubV3API::Issue.should_receive(:new).with(api, :issue_hash1).and_return(:issue1)
@@ -29,7 +29,7 @@ describe GitHubV3API::IssuesAPI do
29
29
 
30
30
  describe '#get' do
31
31
  it 'returns a fully-hydrated Issue object for the specified user, repo, and issue id' do
32
- connection = mock(GitHubV3API)
32
+ connection = double(GitHubV3API)
33
33
  connection.should_receive(:get).with('/repos/octocat/hello-world/issues/1234', {}).and_return(:issue_hash)
34
34
  api = GitHubV3API::IssuesAPI.new(connection)
35
35
  GitHubV3API::Issue.should_receive(:new_with_all_data).with(api, :issue_hash).and_return(:issue)
@@ -37,7 +37,7 @@ describe GitHubV3API::IssuesAPI do
37
37
  end
38
38
 
39
39
  it 'raises GitHubV3API::NotFound instead of a RestClient::ResourceNotFound' do
40
- connection = mock(GitHubV3API)
40
+ connection = double(GitHubV3API)
41
41
  connection.should_receive(:get) \
42
42
  .and_raise(RestClient::ResourceNotFound)
43
43
  api = GitHubV3API::IssuesAPI.new(connection)
@@ -47,7 +47,7 @@ describe GitHubV3API::IssuesAPI do
47
47
 
48
48
  describe "#create" do
49
49
  it 'returns a fully-hydrated Issue object for the specified user, repo, and issue that was created' do
50
- connection = mock(GitHubV3API)
50
+ connection = double(GitHubV3API)
51
51
  data = {:title => "omgbbq"}
52
52
  connection.should_receive(:post).with('/repos/octocat/hello-world/issues', data).and_return(:issue_hash)
53
53
  api = GitHubV3API::IssuesAPI.new(connection)
@@ -56,7 +56,7 @@ describe GitHubV3API::IssuesAPI do
56
56
  end
57
57
 
58
58
  it "raises GitHubV3API::MissingRequiredData when data[:title] is missing" do
59
- connection = mock(GitHubV3API)
59
+ connection = double(GitHubV3API)
60
60
  connection.should_not_receive(:post)
61
61
  api = GitHubV3API::IssuesAPI.new(connection)
62
62
  lambda { api.create('octocat', 'hello-world', {}) }.should raise_error(GitHubV3API::MissingRequiredData)
@@ -65,7 +65,7 @@ describe GitHubV3API::IssuesAPI do
65
65
 
66
66
  describe "#update" do
67
67
  it 'returns a fully-hydrated Issue object for the specified user, repo, and issue that was updated' do
68
- connection = mock(GitHubV3API)
68
+ connection = double(GitHubV3API)
69
69
  data = {:body => "lol, wtf"}
70
70
  connection.should_receive(:patch).with('/repos/octocat/hello-world/issues/1234', data).and_return(:issue_hash)
71
71
  api = GitHubV3API::IssuesAPI.new(connection)
@@ -73,4 +73,4 @@ describe GitHubV3API::IssuesAPI do
73
73
  api.update('octocat', 'hello-world', 1234, data).should == :issue
74
74
  end
75
75
  end
76
- end
76
+ end
@@ -9,7 +9,7 @@ describe GitHubV3API::Org do
9
9
  private_gists private_repos public_gists public_repos space
10
10
  total_private_repos type url)
11
11
  fields.each do |f|
12
- org = GitHubV3API::Org.new_with_all_data(stub('api'), {f.to_s => 'foo'})
12
+ org = GitHubV3API::Org.new_with_all_data(double('api'), {f.to_s => 'foo'})
13
13
  org.methods.should include(f.to_sym)
14
14
  org.send(f).should == 'foo'
15
15
  end
@@ -18,7 +18,7 @@ describe GitHubV3API::Org do
18
18
 
19
19
  describe '#[]' do
20
20
  it 'returns the org data for the specified key' do
21
- api = mock(GitHubV3API::OrgsAPI)
21
+ api = double(GitHubV3API::OrgsAPI)
22
22
  api.should_receive(:get).with('github') \
23
23
  .and_return(GitHubV3API::Org.new(api, 'login' => 'github', 'company' => 'GitHub'))
24
24
  org = GitHubV3API::Org.new(api, 'login' => 'github')
@@ -26,7 +26,7 @@ describe GitHubV3API::Org do
26
26
  end
27
27
 
28
28
  it 'only fetches the data once' do
29
- api = mock(GitHubV3API::OrgsAPI)
29
+ api = double(GitHubV3API::OrgsAPI)
30
30
  api.should_receive(:get).once.with('github') \
31
31
  .and_return(GitHubV3API::Org.new(api, 'login' => 'github', 'company' => 'GitHub'))
32
32
  org = GitHubV3API::Org.new(api, 'login' => 'github')
@@ -38,7 +38,7 @@ describe GitHubV3API::Org do
38
38
 
39
39
  describe '#repos' do
40
40
  it 'returns an array of Repo objects that belong to this org' do
41
- api = mock(GitHubV3API::OrgsAPI)
41
+ api = double(GitHubV3API::OrgsAPI)
42
42
  api.should_receive(:list_repos).with('github').and_return([:repo1, :repo2])
43
43
  org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
44
44
  org.repos.should == [:repo1, :repo2]
@@ -47,7 +47,7 @@ describe GitHubV3API::Org do
47
47
 
48
48
  describe '#members'do
49
49
  it 'returns an array of User objects who are members of this org' do
50
- api = mock(GitHubV3API::OrgsAPI)
50
+ api = double(GitHubV3API::OrgsAPI)
51
51
  api.should_receive(:list_members).with('github').and_return([:user1, :user2])
52
52
 
53
53
  org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
@@ -57,7 +57,7 @@ describe GitHubV3API::Org do
57
57
 
58
58
  describe '#public_members'do
59
59
  it 'returns an array of User objects who are public members of this org' do
60
- api = mock(GitHubV3API::OrgsAPI)
60
+ api = double(GitHubV3API::OrgsAPI)
61
61
  api.should_receive(:list_public_members).with('github').and_return([:user1, :user2])
62
62
 
63
63
  org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe GitHubV3API::OrgsAPI do
4
4
  describe '#list' do
5
5
  it 'returns the public and private orgs for the authenticated user' do
6
- connection = mock(GitHubV3API)
6
+ connection = double(GitHubV3API)
7
7
  connection.should_receive(:get).with('/user/orgs').and_return([:org_hash1, :org_hash2])
8
8
  api = GitHubV3API::OrgsAPI.new(connection)
9
9
  GitHubV3API::Org.should_receive(:new).with(api, :org_hash1).and_return(:org1)
@@ -15,7 +15,7 @@ describe GitHubV3API::OrgsAPI do
15
15
 
16
16
  describe '#get' do
17
17
  it 'returns a fully-hydrated Org object for the specified org login' do
18
- connection = mock(GitHubV3API)
18
+ connection = double(GitHubV3API)
19
19
  connection.should_receive(:get).with('/orgs/octocat').and_return(:org_hash)
20
20
  api = GitHubV3API::OrgsAPI.new(connection)
21
21
  GitHubV3API::Org.should_receive(:new_with_all_data).with(api, :org_hash).and_return(:org)
@@ -25,7 +25,7 @@ describe GitHubV3API::OrgsAPI do
25
25
 
26
26
  describe '#list_repos' do
27
27
  it 'returns the public and private repos for the specified org' do
28
- connection = mock(GitHubV3API, :repos => :repos_api)
28
+ connection = double(GitHubV3API, :repos => :repos_api)
29
29
  connection.should_receive(:get) \
30
30
  .with('/orgs/github/repos') \
31
31
  .and_return([:repo1_hash, :repo2_hash])
@@ -42,7 +42,7 @@ describe GitHubV3API::OrgsAPI do
42
42
 
43
43
  describe '#list_members' do
44
44
  it 'returns the list of members for the specified org' do
45
- connection = mock(GitHubV3API, :users => :users_api)
45
+ connection = double(GitHubV3API, :users => :users_api)
46
46
  connection.should_receive(:get).once.with('/orgs/github/members') \
47
47
  .and_return([:user_hash1, :user_hash2])
48
48
 
@@ -59,7 +59,7 @@ describe GitHubV3API::OrgsAPI do
59
59
 
60
60
  describe '#list_public_members' do
61
61
  it 'returns the list of public members for the specified org' do
62
- connection = mock(GitHubV3API, :users => :users_api)
62
+ connection = double(GitHubV3API, :users => :users_api)
63
63
  connection.should_receive(:get).once.with('/orgs/github/public_members') \
64
64
  .and_return([:user_hash1, :user_hash2])
65
65
 
@@ -7,7 +7,7 @@ describe GitHubV3API::Repo do
7
7
  has_wiki homepage html_url language master_branch name open_issues
8
8
  organization owner parent private pushed_at size source url watchers)
9
9
  fields.each do |f|
10
- repo = GitHubV3API::Repo.new_with_all_data(stub('api'), {f.to_s => 'foo'})
10
+ repo = GitHubV3API::Repo.new_with_all_data(double('api'), {f.to_s => 'foo'})
11
11
  repo.methods.should include(f.to_sym)
12
12
  repo.send(f).should == 'foo'
13
13
  end
@@ -16,14 +16,14 @@ describe GitHubV3API::Repo do
16
16
 
17
17
  describe '#[]' do
18
18
  it 'returns the repo data for the specified key' do
19
- api = stub(GitHubV3API::ReposAPI)
19
+ api = double(GitHubV3API::ReposAPI)
20
20
  repo = GitHubV3API::Repo \
21
21
  .new_with_all_data(api, 'name' => 'hello-world', 'owner' => {'login' => 'octocat'})
22
22
  repo['name'].should == 'hello-world'
23
23
  end
24
24
 
25
25
  it 'only fetches the data once' do
26
- api = mock(GitHubV3API::ReposAPI)
26
+ api = double(GitHubV3API::ReposAPI)
27
27
  api.should_receive(:get).once.with('octocat', 'hello-world') \
28
28
  .and_return(GitHubV3API::Repo.new(api, 'name' => 'hello-world', 'owner' => {'login' => 'octocat'}, 'private' => true))
29
29
  repo = GitHubV3API::Repo.new(api, 'name' => 'hello-world', 'owner' => {'login' => 'octocat'})
@@ -35,7 +35,7 @@ describe GitHubV3API::Repo do
35
35
 
36
36
  describe '#owner_login' do
37
37
  it 'returns the login name of the repo owner' do
38
- api = stub(GitHubV3API::ReposAPI)
38
+ api = double(GitHubV3API::ReposAPI)
39
39
  repo = GitHubV3API::Repo.new_with_all_data(api, 'owner' => {'login' => 'octocat'})
40
40
  repo.owner_login.should == 'octocat'
41
41
  end
@@ -43,7 +43,7 @@ describe GitHubV3API::Repo do
43
43
 
44
44
  describe '#list_collaborators' do
45
45
  it 'returns an array of User objects who are collaborating on this repo' do
46
- api = mock(GitHubV3API::ReposAPI)
46
+ api = double(GitHubV3API::ReposAPI)
47
47
  api.should_receive(:list_collaborators).once.with(
48
48
  'octocat', 'hello-world').and_return([:user1, :user2, :user3])
49
49
 
@@ -55,7 +55,7 @@ describe GitHubV3API::Repo do
55
55
 
56
56
  describe '#list_watchers' do
57
57
  it 'returns an array of User objects who are watching this repo' do
58
- api = mock(GitHubV3API::ReposAPI)
58
+ api = double(GitHubV3API::ReposAPI)
59
59
  api.should_receive(:list_watchers).once.with(
60
60
  'octocat', 'hello-world').and_return([:user1, :user2, :user3])
61
61
 
@@ -67,7 +67,7 @@ describe GitHubV3API::Repo do
67
67
 
68
68
  describe '#list_forks' do
69
69
  it 'returns an array of Repo objects which were forked from this repo' do
70
- api = mock(GitHubV3API::ReposAPI)
70
+ api = double(GitHubV3API::ReposAPI)
71
71
  api.should_receive(:list_forks).once.with(
72
72
  'octocat', 'hello-world').and_return([:repo1, :repo2, :repo3])
73
73
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe GitHubV3API::ReposAPI do
4
4
  describe '#list' do
5
5
  it 'returns the public and private repos for the authenticated user' do
6
- connection = mock(GitHubV3API)
6
+ connection = double(GitHubV3API)
7
7
  connection.should_receive(:get).with('/user/repos').and_return([:repo_hash1, :repo_hash2])
8
8
  api = GitHubV3API::ReposAPI.new(connection)
9
9
  GitHubV3API::Repo.should_receive(:new).with(api, :repo_hash1).and_return(:repo1)
@@ -15,7 +15,7 @@ describe GitHubV3API::ReposAPI do
15
15
 
16
16
  describe '#get' do
17
17
  it 'returns a fully-hydrated Repo object for the specified user and repo name' do
18
- connection = mock(GitHubV3API)
18
+ connection = double(GitHubV3API)
19
19
  connection.should_receive(:get).with('/repos/octocat/hello-world').and_return(:repo_hash)
20
20
  api = GitHubV3API::ReposAPI.new(connection)
21
21
  GitHubV3API::Repo.should_receive(:new_with_all_data).with(api, :repo_hash).and_return(:repo)
@@ -23,7 +23,7 @@ describe GitHubV3API::ReposAPI do
23
23
  end
24
24
 
25
25
  it 'raises GitHubV3API::NotFound instead of a RestClient::ResourceNotFound' do
26
- connection = mock(GitHubV3API)
26
+ connection = double(GitHubV3API)
27
27
  connection.should_receive(:get) \
28
28
  .and_raise(RestClient::ResourceNotFound)
29
29
  api = GitHubV3API::ReposAPI.new(connection)
@@ -33,7 +33,7 @@ describe GitHubV3API::ReposAPI do
33
33
 
34
34
  describe "#list_collaborators" do
35
35
  it 'returns a list of Users who are collaborating on the specified repo' do
36
- connection = mock(GitHubV3API)
36
+ connection = double(GitHubV3API)
37
37
  connection.should_receive(:get).with(
38
38
  '/repos/octocat/hello-world/collaborators').and_return([:user_hash1, :user_hash2])
39
39
  connection.should_receive(:users).twice.and_return(:users_api)
@@ -49,7 +49,7 @@ describe GitHubV3API::ReposAPI do
49
49
 
50
50
  describe "#list_watchers" do
51
51
  it 'returns a list of Users who are watching the specified repo' do
52
- connection = mock(GitHubV3API)
52
+ connection = double(GitHubV3API)
53
53
  connection.should_receive(:get).with(
54
54
  '/repos/octocat/hello-world/watchers').and_return([:user_hash1, :user_hash2])
55
55
  connection.should_receive(:users).twice.and_return(:users_api)
@@ -65,7 +65,7 @@ describe GitHubV3API::ReposAPI do
65
65
 
66
66
  describe "#list_forks" do
67
67
  it 'returns a list of Repos which were forked from the specified repo' do
68
- connection = mock(GitHubV3API)
68
+ connection = double(GitHubV3API)
69
69
  connection.should_receive(:get).with(
70
70
  '/repos/octocat/hello-world/forks').and_return([:repo_hash1, :repo_hash2])
71
71
  api = GitHubV3API::ReposAPI.new(connection)
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe GitHubV3API::UsersAPI do
4
4
  describe '#current' do
5
5
  it 'returns the user data for the authenticated user' do
6
- connection = mock(GitHubV3API)
6
+ connection = double(GitHubV3API)
7
7
  connection.should_receive(:get).with('/user').and_return(:user_hash1)
8
8
  api = GitHubV3API::UsersAPI.new(connection)
9
9
  GitHubV3API::User.should_receive(:new).with(api, :user_hash1).and_return(:user1)
@@ -14,7 +14,7 @@ describe GitHubV3API::UsersAPI do
14
14
 
15
15
  describe '#get' do
16
16
  it 'returns a fully-hydrated User object for the specified user login' do
17
- connection = mock(GitHubV3API)
17
+ connection = double(GitHubV3API)
18
18
  connection.should_receive(:get).with('/users/octocat').and_return(:user_hash)
19
19
  api = GitHubV3API::UsersAPI.new(connection)
20
20
  GitHubV3API::User.should_receive(:new_with_all_data).with(api, :user_hash).and_return(:user)
@@ -8,7 +8,7 @@ describe GitHubV3API::User do
8
8
  html_url created_at type total_private_repos owned_private_repos
9
9
  private_gists disk_usage collaborators)
10
10
  fields.each do |f|
11
- user = GitHubV3API::User.new_with_all_data(stub('api'), {f.to_s => 'foo'})
11
+ user = GitHubV3API::User.new_with_all_data(double('api'), {f.to_s => 'foo'})
12
12
  user.methods.should include(f.to_sym)
13
13
  user.send(f).should == 'foo'
14
14
  end
@@ -17,7 +17,7 @@ describe GitHubV3API::User do
17
17
 
18
18
  describe '#[]' do
19
19
  it 'returns the user data for the specified key' do
20
- api = mock(GitHubV3API::UsersAPI)
20
+ api = double(GitHubV3API::UsersAPI)
21
21
  api.should_receive(:get).with('github') \
22
22
  .and_return(GitHubV3API::User.new(api, 'login' => 'github', 'name' => 'GitHub'))
23
23
  user = GitHubV3API::User.new(api, 'login' => 'github')
@@ -25,7 +25,7 @@ describe GitHubV3API::User do
25
25
  end
26
26
 
27
27
  it 'only fetches the data once' do
28
- api = mock(GitHubV3API::UsersAPI)
28
+ api = double(GitHubV3API::UsersAPI)
29
29
  api.should_receive(:get).once.with('github') \
30
30
  .and_return(GitHubV3API::User.new(api, 'login' => 'github', 'name' => 'GitHub'))
31
31
  user = GitHubV3API::User.new(api, 'login' => 'github')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-v3-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wilger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-29 00:00:00.000000000 Z
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubyforge_project:
169
- rubygems_version: 2.0.3
169
+ rubygems_version: 2.0.14
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Ruby Client for the GitHub v3 API