zemax 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,99 +0,0 @@
1
- require File.expand_path(
2
- File.join(File.dirname(__FILE__), '..', 'spec_helper'))
3
-
4
- module GitHubTest
5
- describe GitHub::Api do
6
- after(:each) do
7
- GitHub::Api.instance.auth.clear
8
- end
9
-
10
- context 'authentication' do
11
- it 'starts out unauthenticated' do
12
- api = described_class.instance
13
- api.should_not be_authenticated
14
- api.auth.should == {}
15
- end
16
-
17
- it 'authenticates with login and token' do
18
- api = described_class.instance
19
- api.auth = joe_auth
20
- api.should be_authenticated
21
- api.auth.should == joe_auth
22
- api.auth.clear
23
- api.should_not be_authenticated
24
- api.auth.should == {}
25
- end
26
- end
27
-
28
- context 'requests' do
29
- before :each do
30
- @api= described_class.instance
31
- @api.auth = joe_auth
32
- @hash = {'name' => 'name', 'description' => 'descr'}
33
- @hash_with_auth = @hash.merge joe_auth
34
- end
35
-
36
- context 'post' do
37
- it 'connects via http, submits post request' do
38
- server, post = stub_server_and_req()
39
- Net::HTTP::Post.should_receive(:new).with('/api/v2/yaml/repos/create').and_return(post)
40
- Net::HTTP.should_receive(:new).with('github.com', 80).and_return(server)
41
- server.should_receive(:request).with(post)
42
-
43
- @api.request(:post, "#{github_yaml}/repos/create", @hash)
44
- end
45
-
46
- it 'connects to github via https, submits post request' do
47
- server, post = stub_server_and_req( :port => 443)
48
- Net::HTTP::Post.should_receive(:new).with('/api/v2/yaml/repos/create').and_return(post)
49
- Net::HTTP.should_receive(:new).with('github.com', 443).and_return(server)
50
- server.should_receive(:request).with(post)
51
-
52
- @api.request(:post, 'https://github.com/api/v2/yaml/repos/create', @hash)
53
- end
54
-
55
- it 'sends form params urlencoded with added authentication' do
56
- server = stub_server
57
- server.should_receive(:request) do |req|
58
- req.content_type.should == 'application/x-www-form-urlencoded'
59
- req.body.should == 'name=name&description=descr&login=joe007&token=b937c8e7ea5a5b47f94eafa39b1e0462'
60
- end
61
-
62
- @api.request(:post, "#{github_yaml}/repos/create", @hash)
63
- end
64
- end
65
-
66
- context 'get' do
67
- it 'connects to github via http, submits get request' do
68
- server, req = stub_server_and_req(:get => true)
69
- Net::HTTP::Get.should_receive(:new).with('/api/v2/yaml/repos/create').and_return(req)
70
- Net::HTTP.should_receive(:new).with('github.com', 80).and_return(server)
71
- server.should_receive(:request).with(req)
72
-
73
- @api.request(:get, "#{github_yaml}/repos/create")
74
- end
75
-
76
- it 'connects to github via https, submits get request' do
77
- server, req = stub_server_and_req(:get => true, :port => 443)
78
- Net::HTTP::Get.should_receive(:new).with('/api/v2/yaml/repos/create').and_return(req)
79
- Net::HTTP.should_receive(:new).with('github.com', 443).and_return(server)
80
- server.should_receive(:request).with(req)
81
-
82
- @api.request(:get, "https://github.com/api/v2/yaml/repos/create")
83
- end
84
-
85
- it 'sends get request with added authentication' do
86
- server = stub_server(:get => true)
87
- server.should_receive(:request) do |req|
88
- req.content_type.should == 'application/x-www-form-urlencoded'
89
- req.body.should == 'login=joe007&token=b937c8e7ea5a5b47f94eafa39b1e0462'
90
- end
91
-
92
- @api.request(:get, "#{github_yaml}/repos/create")
93
- end
94
- end # requests
95
- end
96
- end
97
- end # module GitHubTest
98
-
99
- # EOF
@@ -1,47 +0,0 @@
1
- require File.expand_path(
2
- File.join(File.dirname(__FILE__), '..', 'spec_helper'))
3
-
4
- module GitHubTest
5
- describe GitHub::Base do
6
- after(:each) do
7
- api.auth.clear
8
- end
9
-
10
- context 'general' do
11
- it 'has instance and class method api pointing to the same Api instance' do
12
- api1 = described_class.api
13
- api2 = described_class.new.api
14
- api1.should be_a GitHub::Api
15
- api1.should be_equal api2
16
- api1.should be_equal api
17
- end
18
- end
19
-
20
- context 'requests' do
21
- it 'submits appropriate requests to api as get/post methods (both class and instance)' do
22
- base = described_class.new
23
- api.should_receive(:request).with(:get, '/blah', anything()).twice
24
- base.get ('/blah')
25
- described_class.get ('/blah')
26
-
27
- api.should_receive(:request).with(:post, '/blah', anything()).twice
28
- base.post ('/blah')
29
- described_class.post ('/blah')
30
- end
31
-
32
- it 'prepends get/post calls to api by string set by base_uri class macro' do
33
- base = described_class.new
34
- described_class.class_eval { base_uri 'http://base1.com' }
35
- api.should_receive(:request).with(:get, 'http://base1.com/blah', anything()).twice
36
- base.get ('/blah')
37
- described_class.get ('/blah')
38
-
39
- api.should_receive(:request).with(:post, 'http://base1.com/blah', anything()).twice
40
- base.post ('/blah')
41
- described_class.post ('/blah')
42
- end
43
- end
44
- end
45
- end # module GitHubTest
46
-
47
- # EOF
@@ -1,247 +0,0 @@
1
- require File.expand_path(
2
- File.join(File.dirname(__FILE__), '..', 'spec_helper'))
3
-
4
- module GitHubTest
5
- describe GitHub::Repo do
6
- after(:each) do
7
- api.auth.clear
8
- end
9
-
10
- context '::find as /show/:user)' do
11
- it 'returns an array of repos for a valid github user' do
12
- expect(:get, "#{github_yaml}/repos/show/joe007") do
13
- repos = described_class.find(:user=>'joe007')
14
- repos.should_not be_empty
15
- repos.should be_an Array
16
- repos.should have(3).repos
17
- repos.each {|repo| repo.should be_a described_class}
18
- end
19
- end
20
-
21
- it 'returns repos with "show" attributes set' do
22
- expect(:get, "#{github_yaml}/repos/show/joe007") do
23
- repo = described_class.find(:user=>'joe007').first
24
- repo.name.should == 'fine_repo'
25
- repo.url.should == 'http://github.com/joe007/fine_repo'
26
- repo.clone_url.should == 'git://github.com/joe007/fine_repo.git'
27
- repo.description.should == 'Fine repo by joe'
28
- repo.homepage.should == ''
29
- repo.watchers.should == 3
30
- repo.followers.should == 3
31
- repo.open_issues.should == 0
32
- repo.forks.should == 0
33
- repo.should_not be_fork
34
- repo.should_not be_private
35
- repo.owner.should == 'joe007'
36
- repo.username.should == 'joe007'
37
- end
38
- end
39
-
40
- it 'returns repos with "search" attributes unset' do
41
- expect(:get, "#{github_yaml}/repos/show/joe007") do
42
- repo = described_class.find(:user=>'joe007').first
43
- repo.id.should == nil
44
- repo.language.should == nil
45
- repo.size.should == nil
46
- repo.created.should == nil
47
- repo.pushed.should == nil
48
- repo.score.should == nil
49
- repo.type.should == 'repo'
50
- end
51
- end
52
- end
53
-
54
- context '::find as /search' do
55
- it 'searches github repos with specific search terms' do
56
- expect(:get, "#{github_yaml}/repos/search/joe+repo") do
57
- repos = described_class.find('joe', 'repo')
58
- repos.should_not be_empty
59
- repos.should be_an Array
60
- repos.should have(3).repos
61
- repos.each {|repo| repo.should be_a described_class}
62
- end
63
- end
64
-
65
- it 'returns repos with "search" attributes set' do
66
- expect(:get, "#{github_yaml}/repos/search/joe+repo") do
67
- repo = described_class.find('joe', 'repo').first
68
- repo.name.should == 'fine_repo'
69
- repo.description.should == 'Fine repo by joe'
70
- repo.watchers.should == 3
71
- repo.followers.should == 3
72
- repo.forks.should == 0
73
- repo.should_not be_fork
74
- repo.owner.should == 'joe007'
75
- repo.username.should == 'joe007'
76
- repo.id.should == 'repo-270000'
77
- repo.language.should == ''
78
- repo.size.should == 1228
79
- repo.created.should == '2009-08-06T00:20:39Z'
80
- repo.pushed.should == '2009-11-11T22:58:52Z'
81
- repo.score.should == 4.918499
82
- repo.type.should == 'repo'
83
- repo.clone_url.should == 'git://github.com/joe007/fine_repo.git'
84
- end
85
- end
86
-
87
- it 'returns repos with "show" attributes unset' do
88
- expect(:get, "#{github_yaml}/repos/search/joe+repo") do
89
- repo = described_class.find('joe', 'repo').first
90
- repo.url.should == 'http://github.com/joe007/fine_repo'
91
- repo.homepage.should == nil
92
- repo.open_issues.should == nil
93
- repo.should_not be_private
94
- end
95
- end
96
- end
97
-
98
- context '::find as /show/user/repo' do
99
- it 'finds repo of a (valid) github user' do
100
- expect(:get, "#{github_yaml}/repos/show/joe007/fine_repo") do
101
- repo = described_class.find(:user=>'joe007', :repo=>'fine_repo')
102
- repo.should be_a described_class
103
- repo.name.should == 'fine_repo'
104
- repo.url.should == 'http://github.com/joe007/fine_repo'
105
- repo.clone_url.should == 'git://github.com/joe007/fine_repo.git'
106
- repo.description.should == 'Fine repo by joe'
107
- repo.homepage.should == ''
108
- repo.watchers.should == 1
109
- repo.followers.should == 1
110
- repo.open_issues.should == 0
111
- repo.forks.should == 0
112
- repo.should_not be_fork
113
- repo.should_not be_private
114
- repo.owner.should == 'joe007'
115
- repo.username.should == 'joe007'
116
- end
117
- end
118
-
119
- it 'returns error object instead of non-existing repo' do
120
- expect(:get, "#{github_yaml}/repos/show/joe007/err_repo") do
121
- res = described_class.find(:user=>'joe007', :repo=>'err_repo')
122
- res.should have_key 'error' # res = {"error"=>[{"error"=>"repository not found"}]}
123
- res['error'].should be_kind_of Array
124
- res['error'].first.should have_key 'error'
125
- end
126
- end
127
- end
128
-
129
- context '::create' do
130
- it 'creates new repo for authenticated github user' do
131
- api.auth = joe_auth
132
- keys = {:name => 'new_repo', :description => 'New repo',
133
- :homepage => 'http://joe.org/new_repo', :public => 1}.merge joe_auth
134
- expects(:post, "#{github_yaml}/repos/create", :expected_keys=>keys, :body=>body_from_file('/repos/create'))
135
- repo = described_class.create(:name=>'new_repo', :description => 'New repo',
136
- :homepage => 'http://joe.org/new_repo', :private => false)
137
- repo.should be_a described_class
138
- repo.name.should == 'new_repo'
139
- repo.url.should == 'http://github.com/joe007/new_repo'
140
- repo.clone_url.should == 'git@github.com:joe007/new_repo.git'
141
- repo.description.should == 'New repo'
142
- repo.homepage.should == 'http://joe.org/new_repo'
143
- repo.watchers.should == 1
144
- repo.followers.should == 1
145
- repo.open_issues.should == 0
146
- repo.forks.should == 0
147
- repo.should_not be_fork
148
- repo.should_not be_private
149
- repo.owner.should == 'joe007'
150
- repo.username.should == 'joe007'
151
- end
152
- end
153
-
154
- context '#delete' do
155
- it 'deletes new repo for authenticated github user' do
156
- api.auth = joe_auth
157
- expect(:get, "#{github_yaml}/repos/show/joe007/new_repo")
158
- repo = described_class.find(:repo=>'new_repo')
159
- post1 = { :expected_keys => joe_auth,
160
- :body => body_from_file('/repos/delete/new_repo.1') }
161
- post2 = { :expected_keys => {:delete_token => :any}.merge(joe_auth),
162
- :body => body_from_file('/repos/delete/new_repo.2') }
163
- expects(:post, "#{github_yaml}/repos/delete/new_repo", [post1, post2])
164
- res = repo.delete
165
- res['status'].should == 'deleted'
166
- end
167
- end
168
-
169
- it 'tests' do
170
- pending
171
- api.auth = joe_auth
172
- expect(:get, "#{github_yaml}/repos/showp/joe007/new_repo")
173
- repos = described_class.show('arvicco')
174
- p repos
175
- p repos.map(&:url)
176
- repos.should be_an Array
177
- repos.should_not be_empty
178
- if repos.last.name == 'new_repo'
179
- repos.last.delete
180
- end
181
- true.should == false
182
- end
183
-
184
- # context 'manipulating repos' do
185
- # before (:each) do
186
- # @gh = described_class.new('joerepo')
187
- # @name = "test#{Time.now.to_i}"
188
- # end
189
- # after (:each) do
190
- # @gh.delete_repo @name
191
- # end
192
- #
193
- # it 'creates new repo of a valid github user' do
194
- # @gh.create_repo @name
195
- # repos = @gh.repos
196
- # repos.should_not be_empty
197
- # repos.last[:name].should == @name
198
- # end
199
- #
200
- # it 'creates SINGLE new repo' do
201
- # # Problem: sticky cache
202
- # r = @gh.repos
203
- # p r
204
- # n = r.size
205
- #
206
- # @gh.create_repo @name
207
- # sleep 2
208
- # rr = @gh.repos
209
- # p rr
210
- # rr.size.should == n+1
211
- # end
212
- #
213
- # it 'creates and deletes repo of a valid github user' do
214
- # #creating
215
- # @gh.create_repo @name
216
- # repos = @gh.repos
217
- # repos.should_not be_empty
218
- # repos.last[:name].should == @name
219
- #
220
- # #deleting
221
- # @gh.delete_repo @name
222
- # sleep 2
223
- # repos = @gh.repos
224
- # repos.last[:name].should_not == @name
225
- # repos.find {|r|r[:name] == @name}.should == nil
226
- # #false.should be_true
227
- # end
228
- #
229
- # it 'returns nil if deleting non-existing repo' do
230
- # result = @gh.delete_repo @name
231
- # result.should == nil
232
- # end
233
- #
234
- # it 'does not change repos size if deleting non-existing repo' do
235
- # n = @gh.repos.size
236
- #
237
- # @gh.delete_repo @name
238
- # sleep 1.5
239
- # @gh.repos.should have(n).repos
240
- # end
241
- # end
242
- #
243
- end # describe GitHub::Repo
244
-
245
- end # module GithubTest
246
-
247
- # EOF
@@ -1,24 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Server: nginx/0.7.61
3
- Date: Wed, 30 Dec 2009 14:17:37 GMT
4
- Content-Type: application/x-yaml; charset=utf-8
5
- Connection: keep-alive
6
- Status: 200 OK
7
- ETag: "3448dffce35f5b38d4e477cd57aa7249"
8
- X-Runtime: 76ms
9
- Content-Length: 235
10
- Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
11
- Cache-Control: private, max-age=0, must-revalidate
12
-
13
- ---
14
- repository:
15
- :url: http://github.com/joe007/new_repo
16
- :description: New repo
17
- :forks: 0
18
- :open_issues: 0
19
- :homepage: http://joe.org/new_repo
20
- :fork: false
21
- :private: false
22
- :name: new_repo
23
- :owner: joe007
24
- :watchers: 1
@@ -1,14 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Server: nginx/0.7.61
3
- Date: Wed, 30 Dec 2009 15:04:15 GMT
4
- Content-Type: application/x-yaml; charset=utf-8
5
- Connection: keep-alive
6
- Status: 200 OK
7
- ETag: "71c252d33cdcaab261e3adea39b35dcc"
8
- X-Runtime: 7ms
9
- Content-Length: 30
10
- Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
11
- Cache-Control: private, max-age=0, must-revalidate
12
-
13
- ---
14
- delete_token: jtytnzdcdk
@@ -1,14 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Server: nginx/0.7.61
3
- Date: Wed, 30 Dec 2009 15:05:59 GMT
4
- Content-Type: application/x-yaml; charset=utf-8
5
- Connection: keep-alive
6
- Status: 200 OK
7
- ETag: "2805d28a06ffb58479b7a08117a67714"
8
- X-Runtime: 23ms
9
- Content-Length: 21
10
- Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
11
- Cache-Control: private, max-age=0, must-revalidate
12
-
13
- ---
14
- status: deleted