forked from jwilger/github-v3-api
/
repos_api_spec.rb
33 lines (30 loc) · 1.38 KB
/
repos_api_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'spec_helper'
describe GitHubV3API::ReposAPI do
describe '#list' do
it 'returns the public and private repos for the authenticated user' do
connection = mock(GitHubV3API)
connection.should_receive(:get).with('/user/repos').and_return([:repo_hash1, :repo_hash2])
api = GitHubV3API::ReposAPI.new(connection)
GitHubV3API::Repo.should_receive(:new).with(api, :repo_hash1).and_return(:repo1)
GitHubV3API::Repo.should_receive(:new).with(api, :repo_hash2).and_return(:repo2)
repos = api.list
repos.should == [:repo1, :repo2]
end
end
describe '#get' do
it 'returns a fully-hydrated Repo object for the specified user and repo name' do
connection = mock(GitHubV3API)
connection.should_receive(:get).with('/repos/octocat/hello-world').and_return(:repo_hash)
api = GitHubV3API::ReposAPI.new(connection)
GitHubV3API::Repo.should_receive(:new_with_all_data).with(api, :repo_hash).and_return(:repo)
api.get('octocat', 'hello-world').should == :repo
end
it 'raises GitHubV3API::NotFound instead of a RestClient::ResourceNotFound' do
connection = mock(GitHubV3API)
connection.should_receive(:get) \
.and_raise(RestClient::ResourceNotFound)
api = GitHubV3API::ReposAPI.new(connection)
lambda { api.get('octocat', 'hello-world') }.should raise_error(GitHubV3API::NotFound)
end
end
end