gems 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,16 @@ describe Gems::Client do
4
4
  %w(json xml).each do |format|
5
5
  context ".new(:format => '#{format}')" do
6
6
  before do
7
- @client = Gems::Client.new(:format => format)
7
+ Gems.configure do |config|
8
+ config.format = format
9
+ config.key = '701243f217cdf23b1370c7b66b65ca97'
10
+ config.username = 'nick@gemcutter.org'
11
+ config.password = 'schwwwwing'
12
+ end
13
+ end
14
+
15
+ after do
16
+ Gems.reset
8
17
  end
9
18
 
10
19
  describe ".info" do
@@ -14,7 +23,7 @@ describe Gems::Client do
14
23
  end
15
24
 
16
25
  it "should return some basic information about the given gem" do
17
- info = @client.info 'rails'
26
+ info = Gems.info 'rails'
18
27
  a_get("/api/v1/gems/rails.#{format}").
19
28
  should have_been_made
20
29
  info.name.should == 'rails'
@@ -29,7 +38,7 @@ describe Gems::Client do
29
38
  end
30
39
 
31
40
  it "should return an array of active gems that match the query" do
32
- search = @client.search 'cucumber'
41
+ search = Gems.search 'cucumber'
33
42
  a_get("/api/v1/search.#{format}").
34
43
  with(:query => {"query" => "cucumber"}).
35
44
  should have_been_made
@@ -44,7 +53,7 @@ describe Gems::Client do
44
53
  end
45
54
 
46
55
  it "should return an array of gem version details" do
47
- versions = @client.versions 'coulda'
56
+ versions = Gems.versions 'coulda'
48
57
  a_get("/api/v1/versions/coulda.json").
49
58
  should have_been_made
50
59
  versions.first.number.should == '0.6.3'
@@ -58,7 +67,7 @@ describe Gems::Client do
58
67
  end
59
68
 
60
69
  it "should return the number of downloads by day for a particular gem version" do
61
- downloads = @client.downloads 'coulda', '0.6.3'
70
+ downloads = Gems.downloads 'coulda', '0.6.3'
62
71
  a_get("/api/v1/versions/coulda-0.6.3/downloads.json").
63
72
  should have_been_made
64
73
  downloads["2011-06-22"].should == 8
@@ -73,13 +82,41 @@ describe Gems::Client do
73
82
  end
74
83
 
75
84
  it "should return an array of hashes for all versions of given gems" do
76
- dependencies = @client.dependencies 'rails', 'thor'
85
+ dependencies = Gems.dependencies 'rails', 'thor'
77
86
  a_get("/api/v1/dependencies").
78
87
  with(:query => {"gems" => "rails,thor"}).
79
88
  should have_been_made
80
89
  dependencies.first.number.should == "3.0.9"
81
90
  end
82
91
  end
92
+
93
+ describe ".api_key" do
94
+ before do
95
+ stub_get("/api/v1/api_key").
96
+ to_return(:body => fixture("api_key"))
97
+ end
98
+
99
+ it "should retrieve an API key" do
100
+ api_key = Gems.api_key
101
+ a_get("/api/v1/api_key").
102
+ should have_been_made
103
+ api_key.should == "701243f217cdf23b1370c7b66b65ca97"
104
+ end
105
+ end
106
+
107
+ describe ".gems" do
108
+ before do
109
+ stub_get("/api/v1/gems.#{format}").
110
+ to_return(:body => fixture("gems.#{format}"))
111
+ end
112
+
113
+ it "should list all gems that you own" do
114
+ gems = Gems.gems
115
+ a_get("/api/v1/gems.#{format}").
116
+ should have_been_made
117
+ gems.first.name.should == "congress"
118
+ end
119
+ end
83
120
  end
84
121
  end
85
122
  end
data/spec/gems_spec.rb CHANGED
@@ -3,9 +3,17 @@ require 'helper'
3
3
  describe Gems do
4
4
  context "when delegating to a client" do
5
5
  before do
6
+ Gems.configure do |config|
7
+ config.username = 'nick@gemcutter.org'
8
+ config.password = 'schwwwwing'
9
+ end
6
10
  stub_get("/api/v1/gems/rails.json").to_return(:body => fixture("rails.json"))
7
11
  end
8
12
 
13
+ after do
14
+ Gems.reset
15
+ end
16
+
9
17
  it "should get the correct resource" do
10
18
  Gems.info('rails')
11
19
  a_get("/api/v1/gems/rails.json").should have_been_made
@@ -27,4 +35,41 @@ describe Gems do
27
35
  Gems.new.should be_a Gems::Client
28
36
  end
29
37
  end
38
+
39
+ describe ".format" do
40
+ it "should return the default format" do
41
+ Gems.format.should == Gems::Configuration::DEFAULT_FORMAT
42
+ end
43
+ end
44
+
45
+ describe ".format=" do
46
+ it "should set the format" do
47
+ Gems.format = 'xml'
48
+ Gems.format.should == 'xml'
49
+ end
50
+ end
51
+
52
+ describe ".user_agent" do
53
+ it "should return the default user agent" do
54
+ Gems.user_agent.should == Gems::Configuration::DEFAULT_USER_AGENT
55
+ end
56
+ end
57
+
58
+ describe ".user_agent=" do
59
+ it "should set the user_agent" do
60
+ Gems.user_agent = 'Custom User Agent'
61
+ Gems.user_agent.should == 'Custom User Agent'
62
+ end
63
+ end
64
+
65
+ describe ".configure" do
66
+ Gems::Configuration::VALID_OPTIONS_KEYS.each do |key|
67
+ it "should set the #{key}" do
68
+ Gems.configure do |config|
69
+ config.send("#{key}=", key)
70
+ Gems.send(key).should == key
71
+ end
72
+ end
73
+ end
74
+ end
30
75
  end
data/spec/helper.rb CHANGED
@@ -7,11 +7,11 @@ require 'rspec'
7
7
  require 'webmock/rspec'
8
8
 
9
9
  def a_get(path)
10
- a_request(:get, 'https://rubygems.org' + path)
10
+ a_request(:get, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
11
11
  end
12
12
 
13
13
  def stub_get(path)
14
- stub_request(:get, 'https://rubygems.org' + path)
14
+ stub_request(:get, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
15
15
  end
16
16
 
17
17
  def fixture_path
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gems
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Erik Michaels-Ober
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-24 00:00:00 -07:00
13
+ date: 2011-06-28 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -171,9 +171,12 @@ files:
171
171
  - lib/gems/connection.rb
172
172
  - lib/gems/request.rb
173
173
  - lib/gems/version.rb
174
+ - spec/fixtures/api_key
174
175
  - spec/fixtures/coulda.json
175
176
  - spec/fixtures/dependencies
176
177
  - spec/fixtures/downloads.json
178
+ - spec/fixtures/gems.json
179
+ - spec/fixtures/gems.xml
177
180
  - spec/fixtures/owners.json
178
181
  - spec/fixtures/rails.json
179
182
  - spec/fixtures/rails.xml
@@ -211,9 +214,12 @@ signing_key:
211
214
  specification_version: 3
212
215
  summary: Ruby wrapper for the RubyGems.org API
213
216
  test_files:
217
+ - spec/fixtures/api_key
214
218
  - spec/fixtures/coulda.json
215
219
  - spec/fixtures/dependencies
216
220
  - spec/fixtures/downloads.json
221
+ - spec/fixtures/gems.json
222
+ - spec/fixtures/gems.xml
217
223
  - spec/fixtures/owners.json
218
224
  - spec/fixtures/rails.json
219
225
  - spec/fixtures/rails.xml