git_hub 0.2.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +43 -7
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/git_hub +1 -0
- data/git_hub.gemspec +36 -32
- data/lib/git_hub.rb +3 -5
- data/lib/git_hub/api.rb +8 -13
- data/lib/git_hub/base.rb +44 -42
- data/lib/git_hub/commit.rb +6 -4
- data/lib/git_hub/extensions.rb +25 -0
- data/lib/git_hub/repo.rb +21 -24
- data/lib/git_hub/user.rb +8 -6
- data/spec/git_hub/api_spec.rb +21 -0
- data/spec/git_hub/base_spec.rb +5 -5
- data/spec/git_hub/commit_spec.rb +2 -2
- data/spec/git_hub/extensions_spec.rb +55 -0
- data/spec/git_hub/repo_spec.rb +51 -40
- data/spec/git_hub/user_spec.rb +26 -20
- data/spec/spec_helper.rb +31 -46
- data/spec/stubs/{api_route_error.res → yaml/api_route_error.res} +0 -0
- data/spec/stubs/{commits → yaml/commits}/list/joe007/fine_repo/master.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/list/joe007/fine_repo/master/README.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/show/joe007/fine_repo/3a70f86293b719f193f778a8710b1f83f2f7bf38.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/show/joe007/fine_repo/5e61f0687c40ca48214d09dc7ae2d0d0d8fbfeb8.res +0 -0
- data/spec/stubs/{commits → yaml/commits}/show/joe007/fine_repo/f7f5dddaa37deacc83f1f56876e2b135389d03ab.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.1.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.2.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.3.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/create.4.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/delete/new_repo.1.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/delete/new_repo.2.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/delete/new_repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/search/fine+repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/search/joe+repo.res +0 -0
- data/spec/stubs/yaml/repos/show/invalid_github_user/err_repo.res +14 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/err_repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/fine_repo.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/fine_repo/branches.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/fine_repo/tags.res +0 -0
- data/spec/stubs/{repos → yaml/repos}/show/joe007/new_repo.res +0 -0
- data/spec/stubs/{user → yaml/user}/follow/arvicco.res +0 -0
- data/spec/stubs/{user → yaml/user}/search/joe+007.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/arvicco.res +0 -0
- data/spec/stubs/{user/show/joe_is_not_github_user.res → yaml/user/show/invalid_github_user.res} +7 -3
- data/spec/stubs/{user → yaml/user}/show/joe007.auth.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007/followers.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007/following.empty.res +0 -0
- data/spec/stubs/{user → yaml/user}/show/joe007/following.res +0 -0
- metadata +36 -32
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec'
|
2
|
-
require 'cgi'
|
3
2
|
require 'fakeweb'
|
4
3
|
require 'fakeweb_matcher'
|
5
4
|
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib git_hub]))
|
@@ -26,64 +25,41 @@ Spec::Runner.configure do |config|
|
|
26
25
|
config.extend(SpecMacros)
|
27
26
|
end
|
28
27
|
|
29
|
-
module GitHubTest
|
28
|
+
module GitHubTest
|
30
29
|
|
31
30
|
# Test related Constants:
|
32
|
-
TEST_FAKE_WEB =
|
31
|
+
TEST_FAKE_WEB = true # turning this flag on routes all Net calls to local stubs
|
33
32
|
|
34
|
-
|
35
|
-
def use
|
36
|
-
lambda {yield}.should_not raise_error
|
37
|
-
end
|
33
|
+
API = GitHub::Api.instance
|
38
34
|
|
39
35
|
# Extract response from file
|
40
|
-
def response_from_file(file_path, uri_path='')
|
36
|
+
def response_from_file( file_path, uri_path = '' )
|
41
37
|
filename = File.join(File.dirname(__FILE__), 'stubs', file_path + '.res')
|
42
38
|
unless File.exists?(filename) && !File.directory?(filename)
|
43
|
-
raise "No stub file #{filename}. To obtain it use:\n#{curl_string(
|
39
|
+
raise "No stub file #{filename}. To obtain it use:\n#{curl_string(filename, uri_path)}"
|
44
40
|
end
|
45
41
|
filename
|
46
42
|
end
|
47
43
|
|
48
|
-
|
44
|
+
# Curl command to retrieve non-existent stub file
|
45
|
+
def curl_string( filename, uri_path )
|
49
46
|
if api.authenticated?
|
50
47
|
"curl -i -d \"login=#{api.auth['login']}&token=#{api.auth['token']}\" #{uri_path} > #{filename}"
|
51
48
|
else
|
52
|
-
"curl -i #{
|
49
|
+
"curl -i #{uri_path} > #{filename}"
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
|
-
# Stubs github server, with options:
|
57
|
-
# :host:: Host name - default 'github.com'
|
58
|
-
# :port:: Port - default 80
|
59
|
-
def stub_server(options={})
|
60
|
-
server = Net::HTTP.new(options[:host] ||'github.com', options[:port] || 80)
|
61
|
-
Net::HTTP.stub!(:new).and_return(server)
|
62
|
-
server
|
63
|
-
end
|
64
|
-
|
65
|
-
# Stubs http request, with options:
|
66
|
-
# :path:: Request path - default '/api/v2/yaml/repos/create'
|
67
|
-
# :get:: Indicates that request is get, otherwise post
|
68
|
-
def stub_req(options={})
|
69
|
-
path = options[:path] || '/api/v2/yaml/repos/create'
|
70
|
-
options[:get] ? Net::HTTP::Get.new(path) : Net::HTTP::Post.new(path)
|
71
|
-
end
|
72
|
-
|
73
|
-
def stub_server_and_req(options = {})
|
74
|
-
[stub_server(options), stub_req(options)]
|
75
|
-
end
|
76
|
-
|
77
53
|
# Converts path to uri, registers it with FakeWeb with stub file at stubs/(http)/path as a response
|
78
54
|
# If extensions given (possibly as an Array), looks for stub files with extensions, responds in sequence
|
79
55
|
# If block is given, yields to block and checks that registered uri was hit during block execution
|
80
|
-
def expect(method, path, extensions = nil)
|
81
|
-
uri_path = path
|
56
|
+
def expect( method, path, extensions = nil )
|
82
57
|
if TEST_FAKE_WEB
|
58
|
+
uri_path = path
|
83
59
|
[extensions].flatten.each do |ext|
|
84
60
|
case path
|
85
61
|
when Regexp.new(github_yaml)
|
86
|
-
file_path = path.sub(github_yaml, '')
|
62
|
+
file_path = path.sub(github_yaml, '/yaml')
|
87
63
|
when Regexp.new(github_http)
|
88
64
|
file_path = path.sub(github_http, '/http')
|
89
65
|
else
|
@@ -102,9 +78,14 @@ module GitHubTest
|
|
102
78
|
end
|
103
79
|
end
|
104
80
|
|
105
|
-
#
|
81
|
+
# Remove authentication
|
82
|
+
def clear_auth
|
83
|
+
API.auth.clear
|
84
|
+
end
|
85
|
+
|
86
|
+
# Authenticate as joe
|
106
87
|
def authenticate_as_joe
|
107
|
-
|
88
|
+
API.auth = joe_auth
|
108
89
|
end
|
109
90
|
|
110
91
|
def joe_auth
|
@@ -116,7 +97,7 @@ module GitHubTest
|
|
116
97
|
GitHub::User.find(:user=>'joe007')
|
117
98
|
end
|
118
99
|
|
119
|
-
def github_http
|
100
|
+
def github_http
|
120
101
|
'http://github.com'
|
121
102
|
end
|
122
103
|
|
@@ -124,16 +105,19 @@ module GitHubTest
|
|
124
105
|
'http://github.com/api/v2/yaml'
|
125
106
|
end
|
126
107
|
|
127
|
-
|
128
|
-
|
108
|
+
# repo name for 'new_repo' for real life tests - needed because GitHub
|
109
|
+
# gets stuck after several attempts to create repo with the same name
|
110
|
+
def new_repo
|
111
|
+
@new_repo_name ||= TEST_FAKE_WEB ? 'new_repo' : "new_repo#{Time.now.strftime("%Y%m%d-%H%M%S")}"
|
129
112
|
end
|
130
113
|
|
114
|
+
# waits a little bit - needed because cache is sticky on real github
|
131
115
|
def wait
|
132
|
-
sleep 1 unless TEST_FAKE_WEB
|
116
|
+
sleep 1 unless TEST_FAKE_WEB
|
133
117
|
end
|
134
118
|
|
135
119
|
# specific expectations used in more than one spec file
|
136
|
-
def should_be_commit commit, type
|
120
|
+
def should_be_commit( commit, type )
|
137
121
|
arvicco = { 'name'=> 'arvicco', 'email'=> 'arvitallian@gmail.com'}
|
138
122
|
commit.should be_a GitHub::Commit
|
139
123
|
commit.author.should == arvicco
|
@@ -142,18 +126,19 @@ module GitHubTest
|
|
142
126
|
commit.repo.should == 'fine_repo'
|
143
127
|
case type.to_s
|
144
128
|
when '5e61'
|
129
|
+
commit.parents.should == [{"id"=>"f7f5dddaa37deacc83f1f56876e2b135389d03ab"}]
|
145
130
|
commit.sha.should == '5e61f0687c40ca48214d09dc7ae2d0d0d8fbfeb8'
|
146
131
|
commit.url.should == 'http://github.com/joe007/fine_repo/commit/5e61f0687c40ca48214d09dc7ae2d0d0d8fbfeb8'
|
147
|
-
commit.
|
148
|
-
commit.
|
132
|
+
commit.committed.should == Time.parse("2010-01-08T02:49:26-08:00")
|
133
|
+
commit.authored.should == Time.parse("2010-01-08T02:49:26-08:00")
|
149
134
|
commit.message.should == 'Version bump to 0.1.2'
|
150
135
|
commit.tree.should == '917a288e375020ac4c0f4413dc6f23d6f06fc51b'
|
151
136
|
when '543b'
|
152
137
|
commit.parents.should == []
|
153
138
|
commit.sha.should == '4f223bdbbfe6acade73f4b81d089f0705b07d75d'
|
154
139
|
commit.url.should == 'http://github.com/joe007/fine_repo/commit/4f223bdbbfe6acade73f4b81d089f0705b07d75d'
|
155
|
-
commit.
|
156
|
-
commit.
|
140
|
+
commit.committed.should == Time.parse("2010-01-08T01:20:55-08:00")
|
141
|
+
commit.authored.should == Time.parse("2010-01-08T01:20:55-08:00")
|
157
142
|
commit.message.should == 'First commit'
|
158
143
|
commit.tree.should == '543b9bebdc6bd5c4b22136034a95dd097a57d3dd'
|
159
144
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
HTTP/1.1 403 Forbidden
|
2
|
+
Server: nginx/0.7.61
|
3
|
+
Date: Fri, 15 Jan 2010 10:30:10 GMT
|
4
|
+
Content-Type: application/x-yaml; charset=utf-8
|
5
|
+
Connection: keep-alive
|
6
|
+
Status: 403 Forbidden
|
7
|
+
X-Runtime: 3ms
|
8
|
+
Content-Length: 43
|
9
|
+
Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
|
10
|
+
Cache-Control: no-cache
|
11
|
+
|
12
|
+
---
|
13
|
+
error:
|
14
|
+
- error: repository not found
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/stubs/{user/show/joe_is_not_github_user.res → yaml/user/show/invalid_github_user.res}
RENAMED
@@ -1,8 +1,8 @@
|
|
1
1
|
HTTP/1.1 404 Not Found
|
2
2
|
Server: nginx/0.7.61
|
3
|
-
Date:
|
3
|
+
Date: Fri, 15 Jan 2010 10:27:53 GMT
|
4
4
|
Content-Type: text/html
|
5
|
-
Content-Length:
|
5
|
+
Content-Length: 3773
|
6
6
|
Connection: keep-alive
|
7
7
|
|
8
8
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
@@ -73,7 +73,11 @@ Connection: keep-alive
|
|
73
73
|
<a href="http://twitter.com/github">Status</a>
|
74
74
|
</div>
|
75
75
|
<div class="company">
|
76
|
-
|
76
|
+
©
|
77
|
+
2010
|
78
|
+
GitHub Inc.
|
79
|
+
All rights reserved.
|
80
|
+
| <a href="http://github.com/site/terms">Terms of Service</a> | <a href="http://github.com/site/privacy">Privacy Policy</a>
|
77
81
|
</div>
|
78
82
|
</div>
|
79
83
|
<div class="sponsor">
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arvicco
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-16 00:00:00 +03:00
|
13
13
|
default_executable: git_hub
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,46 +55,49 @@ files:
|
|
55
55
|
- lib/git_hub/api.rb
|
56
56
|
- lib/git_hub/base.rb
|
57
57
|
- lib/git_hub/commit.rb
|
58
|
+
- lib/git_hub/extensions.rb
|
58
59
|
- lib/git_hub/repo.rb
|
59
60
|
- lib/git_hub/user.rb
|
60
61
|
- spec/git_hub/api_spec.rb
|
61
62
|
- spec/git_hub/base_spec.rb
|
62
63
|
- spec/git_hub/commit_spec.rb
|
64
|
+
- spec/git_hub/extensions_spec.rb
|
63
65
|
- spec/git_hub/repo_spec.rb
|
64
66
|
- spec/git_hub/user_spec.rb
|
65
67
|
- spec/spec.opts
|
66
68
|
- spec/spec_helper.rb
|
67
|
-
- spec/stubs/api_route_error.res
|
68
|
-
- spec/stubs/commits/list/joe007/fine_repo/master.res
|
69
|
-
- spec/stubs/commits/list/joe007/fine_repo/master/README.res
|
70
|
-
- spec/stubs/commits/show/joe007/fine_repo/3a70f86293b719f193f778a8710b1f83f2f7bf38.res
|
71
|
-
- spec/stubs/commits/show/joe007/fine_repo/5e61f0687c40ca48214d09dc7ae2d0d0d8fbfeb8.res
|
72
|
-
- spec/stubs/commits/show/joe007/fine_repo/f7f5dddaa37deacc83f1f56876e2b135389d03ab.res
|
73
69
|
- spec/stubs/http/users/follow.res
|
74
|
-
- spec/stubs/
|
75
|
-
- spec/stubs/
|
76
|
-
- spec/stubs/
|
77
|
-
- spec/stubs/
|
78
|
-
- spec/stubs/
|
79
|
-
- spec/stubs/
|
80
|
-
- spec/stubs/repos/
|
81
|
-
- spec/stubs/repos/
|
82
|
-
- spec/stubs/repos/
|
83
|
-
- spec/stubs/repos/
|
84
|
-
- spec/stubs/repos/
|
85
|
-
- spec/stubs/repos/
|
86
|
-
- spec/stubs/repos/
|
87
|
-
- spec/stubs/repos/
|
88
|
-
- spec/stubs/repos/
|
89
|
-
- spec/stubs/
|
90
|
-
- spec/stubs/
|
91
|
-
- spec/stubs/
|
92
|
-
- spec/stubs/
|
93
|
-
- spec/stubs/
|
94
|
-
- spec/stubs/
|
95
|
-
- spec/stubs/
|
96
|
-
- spec/stubs/user/
|
97
|
-
- spec/stubs/user/
|
70
|
+
- spec/stubs/yaml/api_route_error.res
|
71
|
+
- spec/stubs/yaml/commits/list/joe007/fine_repo/master.res
|
72
|
+
- spec/stubs/yaml/commits/list/joe007/fine_repo/master/README.res
|
73
|
+
- spec/stubs/yaml/commits/show/joe007/fine_repo/3a70f86293b719f193f778a8710b1f83f2f7bf38.res
|
74
|
+
- spec/stubs/yaml/commits/show/joe007/fine_repo/5e61f0687c40ca48214d09dc7ae2d0d0d8fbfeb8.res
|
75
|
+
- spec/stubs/yaml/commits/show/joe007/fine_repo/f7f5dddaa37deacc83f1f56876e2b135389d03ab.res
|
76
|
+
- spec/stubs/yaml/repos/create.1.res
|
77
|
+
- spec/stubs/yaml/repos/create.2.res
|
78
|
+
- spec/stubs/yaml/repos/create.3.res
|
79
|
+
- spec/stubs/yaml/repos/create.4.res
|
80
|
+
- spec/stubs/yaml/repos/delete/new_repo.1.res
|
81
|
+
- spec/stubs/yaml/repos/delete/new_repo.2.res
|
82
|
+
- spec/stubs/yaml/repos/delete/new_repo.res
|
83
|
+
- spec/stubs/yaml/repos/search/fine+repo.res
|
84
|
+
- spec/stubs/yaml/repos/search/joe+repo.res
|
85
|
+
- spec/stubs/yaml/repos/show/invalid_github_user/err_repo.res
|
86
|
+
- spec/stubs/yaml/repos/show/joe007.res
|
87
|
+
- spec/stubs/yaml/repos/show/joe007/err_repo.res
|
88
|
+
- spec/stubs/yaml/repos/show/joe007/fine_repo.res
|
89
|
+
- spec/stubs/yaml/repos/show/joe007/fine_repo/branches.res
|
90
|
+
- spec/stubs/yaml/repos/show/joe007/fine_repo/tags.res
|
91
|
+
- spec/stubs/yaml/repos/show/joe007/new_repo.res
|
92
|
+
- spec/stubs/yaml/user/follow/arvicco.res
|
93
|
+
- spec/stubs/yaml/user/search/joe+007.res
|
94
|
+
- spec/stubs/yaml/user/show/arvicco.res
|
95
|
+
- spec/stubs/yaml/user/show/invalid_github_user.res
|
96
|
+
- spec/stubs/yaml/user/show/joe007.auth.res
|
97
|
+
- spec/stubs/yaml/user/show/joe007.res
|
98
|
+
- spec/stubs/yaml/user/show/joe007/followers.res
|
99
|
+
- spec/stubs/yaml/user/show/joe007/following.empty.res
|
100
|
+
- spec/stubs/yaml/user/show/joe007/following.res
|
98
101
|
has_rdoc: true
|
99
102
|
homepage: http://github.com/arvicco/git_hub
|
100
103
|
licenses: []
|
@@ -127,6 +130,7 @@ test_files:
|
|
127
130
|
- spec/git_hub/api_spec.rb
|
128
131
|
- spec/git_hub/base_spec.rb
|
129
132
|
- spec/git_hub/commit_spec.rb
|
133
|
+
- spec/git_hub/extensions_spec.rb
|
130
134
|
- spec/git_hub/repo_spec.rb
|
131
135
|
- spec/git_hub/user_spec.rb
|
132
136
|
- spec/spec_helper.rb
|