Skip to content

Commit aa94244

Browse files
committed
Add specs for contents api.
1 parent 400d951 commit aa94244

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

spec/fixtures/repos/content.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"type": "file",
3+
"encoding": "base64",
4+
"_links": {
5+
"git": "https://api.github.com/repos/pengwynn/octokit/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
6+
"self": "https://api.github.com/repos/pengwynn/octokit/contents/README.md",
7+
"html": "https://github.com/pengwynn/octokit/blob/master/README.md"
8+
},
9+
"size": 5362,
10+
"name": "README.md",
11+
"path": "README.md",
12+
"content": "encoded content ...",
13+
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1"
14+
}

spec/fixtures/repos/readme.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"type": "file",
3+
"encoding": "base64",
4+
"_links": {
5+
"git": "https://api.github.com/repos/pengwynn/octokit/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
6+
"self": "https://api.github.com/repos/pengwynn/octokit/contents/README.md",
7+
"html": "https://github.com/pengwynn/octokit/blob/master/README.md"
8+
},
9+
"size": 5362,
10+
"name": "README.md",
11+
"path": "README.md",
12+
"content": "encoded content ...",
13+
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1"
14+
}

spec/github/repos/contents_spec.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Repos::Contents do
6+
let(:github) { Github.new }
7+
let(:user) { 'octokit' }
8+
let(:repo) { 'github' }
9+
10+
after { reset_authentication_for(github) }
11+
12+
context "#readme" do
13+
before do
14+
stub_get("/repos/#{user}/#{repo}/readme").
15+
to_return(:body => fixture('repos/readme.json'), :status => 200,
16+
:headers => {:content_type => "application/json; charset=utf-8"})
17+
end
18+
19+
it "should get the resources" do
20+
github.repos.contents.readme user, repo
21+
a_get("/repos/#{user}/#{repo}/readme").should have_been_made
22+
end
23+
24+
it "should get readme information" do
25+
readme= github.repos.contents.readme user, repo
26+
readme.name.should == 'README.md'
27+
end
28+
end
29+
30+
context "#get" do
31+
let(:path) { 'README.md' }
32+
33+
before do
34+
stub_get("/repos/#{user}/#{repo}/contents/#{path}").
35+
to_return(:body => fixture('repos/content.json'), :status => 200,
36+
:headers => {:content_type => "application/json; charset=utf-8"})
37+
end
38+
39+
it "should get the resources" do
40+
github.repos.contents.get user, repo, path
41+
a_get("/repos/#{user}/#{repo}/contents/#{path}").should have_been_made
42+
end
43+
44+
it "should get repository information" do
45+
content = github.repos.contents.get user, repo, path
46+
content.name.should == 'README.md'
47+
end
48+
end
49+
50+
context "#users" do
51+
let(:archive_format) { 'tarball' }
52+
let(:ref) { 'master' }
53+
54+
before do
55+
stub_get("/repos/#{user}/#{repo}/#{archive_format}/#{ref}").
56+
to_return(:body => '', :status => 302)
57+
end
58+
59+
it "should get the resources" do
60+
github.repos.contents.archive user, repo, :archive_format => archive_format, :ref => ref
61+
a_get("/repos/#{user}/#{repo}/#{archive_format}/#{ref}").should have_been_made
62+
end
63+
end
64+
65+
end # Github::Repos::Contents

0 commit comments

Comments
 (0)