crohr-restfully 0.1.1 → 0.2.1
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.
- data/README.rdoc +70 -2
- data/Rakefile +38 -9
- data/TODO.rdoc +3 -0
- data/VERSION +1 -1
- data/bin/restfully +8 -8
- data/examples/grid5000.rb +2 -1
- data/lib/restfully/collection.rb +12 -16
- data/lib/restfully/error.rb +4 -0
- data/lib/restfully/http/adapters/abstract_adapter.rb +30 -0
- data/lib/restfully/http/adapters/patron_adapter.rb +16 -0
- data/lib/restfully/http/adapters/rest_client_adapter.rb +31 -0
- data/lib/restfully/http/error.rb +20 -0
- data/lib/restfully/http/headers.rb +20 -0
- data/lib/restfully/http/request.rb +24 -0
- data/lib/restfully/http/response.rb +19 -0
- data/lib/restfully/http.rb +9 -0
- data/lib/restfully/parsing.rb +7 -7
- data/lib/restfully/resource.rb +15 -18
- data/lib/restfully/session.rb +41 -41
- data/lib/restfully.rb +12 -5
- data/restfully.gemspec +29 -5
- data/spec/collection_spec.rb +73 -17
- data/spec/fixtures/grid5000-sites.json +489 -0
- data/spec/http/error_spec.rb +18 -0
- data/spec/http/headers_spec.rb +17 -0
- data/spec/http/request_spec.rb +45 -0
- data/spec/http/response_spec.rb +15 -0
- data/spec/http/rest_client_adapter_spec.rb +33 -0
- data/spec/parsing_spec.rb +25 -0
- data/spec/resource_spec.rb +109 -60
- data/spec/restfully_spec.rb +9 -1
- data/spec/session_spec.rb +97 -13
- data/spec/spec_helper.rb +3 -1
- metadata +27 -4
data/spec/resource_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Resource do
|
|
7
7
|
@logger = Logger.new(STDOUT)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "should have all methods of a hash" do
|
10
|
+
it "should have all the methods of a hash" do
|
11
11
|
resource = Resource.new("uri", session=mock('session'))
|
12
12
|
resource.size.should == 0
|
13
13
|
resource['whatever'] = 'thing'
|
@@ -46,57 +46,78 @@ describe Resource do
|
|
46
46
|
before do
|
47
47
|
@raw = {
|
48
48
|
'links' => [
|
49
|
-
{'rel' => 'self', 'href' => '/sites/rennes
|
50
|
-
{'rel' => '
|
49
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes'},
|
50
|
+
{'rel' => 'parent', 'href' => '/grid5000'},
|
51
51
|
{'rel' => 'invalid_rel', 'href' => '/whatever'},
|
52
|
-
{'rel' => '
|
53
|
-
{'rel' => '
|
54
|
-
{'rel' => 'collection', 'href' => '/sites/rennes/
|
55
|
-
{'rel' => 'collection', 'href' => '/sites/rennes/
|
52
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/status', 'title' => 'status'},
|
53
|
+
{'rel' => 'member', 'href' => '/grid5000/sites/rennes/versions/123', 'title' => 'version'},
|
54
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/versions', 'resolvable' => false, 'title' => 'versions'},
|
55
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/clusters', 'resolvable' => true, 'resolved' => true, 'title' => 'clusters'},
|
56
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/environments/versions/123', 'resolvable' => true, 'resolved' => false, 'title' => 'environments'},
|
56
57
|
{'rel' => 'collection', 'href' => '/has/no/title'}
|
57
58
|
],
|
58
59
|
'uid' => 'rennes',
|
59
60
|
'whatever' => 'whatever',
|
60
61
|
'an_array' => [1, 2, 3],
|
61
62
|
'clusters' => {
|
62
|
-
'
|
63
|
-
'
|
63
|
+
'paradent' => {
|
64
|
+
'uid' => 'paradent',
|
64
65
|
'links' => [
|
65
|
-
{'rel' => 'self', 'href' => '/sites/rennes/clusters/paradent
|
66
|
-
{'rel' => 'parent', 'href' => '/sites/rennes
|
67
|
-
{'rel' => 'collection', 'href' => '/sites/rennes/clusters/paradent/nodes
|
68
|
-
{'rel' => 'collection', 'href' => '/sites/rennes/clusters/paradent/versions', 'resolvable' => false, 'title' => 'versions'},
|
69
|
-
{'rel' => 'member', 'href' => '/sites/rennes/clusters/paradent/
|
66
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes/clusters/paradent'},
|
67
|
+
{'rel' => 'parent', 'href' => '/grid5000/sites/rennes'},
|
68
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/clusters/paradent/nodes', 'title' => 'nodes', 'resolvable' => true, 'resolved' => false},
|
69
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/clusters/paradent/versions', 'resolvable' => false, 'title' => 'versions'},
|
70
|
+
{'rel' => 'member', 'href' => '/grid5000/sites/rennes/clusters/paradent/versions/123', 'title' => 'version'},
|
71
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/clusters/paradent/status', 'title' => 'status'}
|
70
72
|
],
|
71
73
|
'model' => 'XYZ'
|
72
74
|
},
|
73
|
-
'
|
74
|
-
'
|
75
|
+
'paramount' => {
|
76
|
+
'uid' => 'paramount',
|
75
77
|
'links' => [
|
76
|
-
{'rel' => 'self', 'href' => '/sites/rennes/clusters/paramount
|
77
|
-
{'rel' => 'parent', 'href' => '/sites/rennes
|
78
|
-
{'rel' => 'collection', 'href' => '/sites/rennes/clusters/paramount/nodes
|
79
|
-
{'rel' => 'collection', 'href' => '/sites/rennes/clusters/paramount/versions', 'resolvable' => false, 'title' => 'versions'},
|
80
|
-
{'rel' => 'member', 'href' => '/sites/rennes/clusters/paramount/
|
78
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes/clusters/paramount'},
|
79
|
+
{'rel' => 'parent', 'href' => '/grid5000/sites/rennes'},
|
80
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/clusters/paramount/nodes', 'title' => 'nodes', 'resolvable' => true, 'resolved' => false},
|
81
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/clusters/paramount/versions', 'resolvable' => false, 'title' => 'versions'},
|
82
|
+
{'rel' => 'member', 'href' => '/grid5000/sites/rennes/clusters/paramount/versions/123', 'title' => 'version'},
|
83
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/clusters/paramount/status', 'title' => 'status'}
|
81
84
|
],
|
82
85
|
'model' => 'XYZ1b'
|
83
86
|
}
|
84
87
|
}
|
85
|
-
}
|
88
|
+
}.to_json
|
89
|
+
@response_200 = Restfully::HTTP::Response.new(200, {'Content-Type' => 'application/json;utf-8', 'Content-Length' => @raw.length}, @raw)
|
86
90
|
end
|
87
91
|
it "should not be loaded in its initial state" do
|
88
|
-
resource = Resource.new("uri", mock('session'))
|
92
|
+
resource = Resource.new(mock("uri"), mock('session'))
|
89
93
|
resource.should_not be_loaded
|
90
94
|
end
|
91
95
|
it "should get the raw representation of the resource via the session if it doesn't have it" do
|
92
|
-
resource = Resource.new("uri", session = mock("session", :logger => Logger.new(STDOUT)))
|
96
|
+
resource = Resource.new(uri=mock("uri"), session = mock("session", :logger => Logger.new(STDOUT)))
|
93
97
|
resource.stub!(:define_link) # do not define links
|
94
98
|
resource.raw.should be_nil
|
95
|
-
session.should_receive(:get).with(
|
99
|
+
session.should_receive(:get).with(uri, {}).and_return(@response_200)
|
96
100
|
resource.load
|
101
|
+
resource.should be_loaded
|
102
|
+
end
|
103
|
+
it "should get the raw representation of the resource via the session if there are query parameters" do
|
104
|
+
resource = Resource.new(uri=mock("uri"), session = mock("session", :logger => Logger.new(STDOUT)))
|
105
|
+
resource.stub!(:define_link) # do not define links
|
106
|
+
resource.stub!(:loaded?).and_return(true) # should force reload even if already loaded
|
107
|
+
resource.raw.should be_nil
|
108
|
+
session.should_receive(:get).with(uri, {:query => {:q1 => 'v1'}}).and_return(@response_200)
|
109
|
+
resource.load(:query => {:q1 => 'v1'})
|
110
|
+
end
|
111
|
+
it "should get the raw representation of the resource if forced to do so" do
|
112
|
+
resource = Resource.new(uri=mock("uri"), session = mock("session", :logger => Logger.new(STDOUT)))
|
113
|
+
resource.stub!(:define_link) # do not define links
|
114
|
+
resource.stub!(:loaded?).and_return(true) # should force reload even if already loaded
|
115
|
+
resource.raw.should be_nil
|
116
|
+
session.should_receive(:get).with(uri, {}).and_return(@response_200)
|
117
|
+
resource.load(:reload => true)
|
97
118
|
end
|
98
119
|
it "should correctly define the functions to access simple values" do
|
99
|
-
resource = Resource.new("uri", session = mock("session", :get => @
|
120
|
+
resource = Resource.new("uri", session = mock("session", :get => @response_200, :logger => @logger))
|
100
121
|
resource.stub!(:define_link) # do not define links
|
101
122
|
resource.load
|
102
123
|
resource['whatever'].should == 'whatever'
|
@@ -107,43 +128,71 @@ describe Resource do
|
|
107
128
|
lambda{resource.clusters}.should raise_error(NoMethodError)
|
108
129
|
end
|
109
130
|
|
110
|
-
it "should correctly define
|
111
|
-
resource = Resource.new("uri", session = mock("session", :get =>
|
131
|
+
it "should correctly define a collection association" do
|
132
|
+
resource = Resource.new("uri", session = mock("session", :get => mock("restfully response", :body => {
|
133
|
+
'links' => [
|
134
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes'},
|
135
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/versions', 'resolvable' => false, 'title' => 'versions'}
|
136
|
+
],
|
137
|
+
'uid' => 'rennes'
|
138
|
+
}), :logger => @logger))
|
139
|
+
Collection.should_receive(:new).with('/grid5000/sites/rennes/versions', session, :title => 'versions', :raw => nil).and_return(collection=mock("restfully collection"))
|
140
|
+
resource.load
|
141
|
+
resource.associations['versions'].should == collection
|
142
|
+
end
|
143
|
+
it "should NOT update the URI with the self link" do
|
144
|
+
resource = Resource.new("uri", session = mock("session", :get => mock("restfully response", :body => {
|
145
|
+
'links' => [
|
146
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes'}
|
147
|
+
],
|
148
|
+
'uid' => 'rennes'
|
149
|
+
}), :logger => @logger))
|
150
|
+
resource.uri.should == "uri"
|
151
|
+
resource.load
|
152
|
+
resource.uri.should == "uri"
|
153
|
+
end
|
154
|
+
it "should correctly define a member association" do
|
155
|
+
resource = Resource.new("uri", session = mock("session", :get => mock("restfully response", :body => {
|
156
|
+
'links' => [
|
157
|
+
{'rel' => 'member', 'href' => '/grid5000/sites/rennes/versions/123', 'title' => 'version'}
|
158
|
+
],
|
159
|
+
'uid' => 'rennes'
|
160
|
+
}), :logger => @logger))
|
161
|
+
Resource.should_receive(:new).with('/grid5000/sites/rennes/versions/123', session, :title => 'version', :raw => nil).and_return(member=mock("restfully resource"))
|
162
|
+
resource.load
|
163
|
+
resource.associations['version'].should == member
|
164
|
+
end
|
165
|
+
it "should correctly define a parent association" do
|
166
|
+
resource = Resource.new("uri", session = mock("session", :get => mock("restfully response", :body => {
|
167
|
+
'links' => [
|
168
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes'},
|
169
|
+
{'rel' => 'parent', 'href' => '/grid5000'}
|
170
|
+
],
|
171
|
+
'uid' => 'rennes'
|
172
|
+
}), :logger => @logger))
|
173
|
+
Resource.should_receive(:new).with('/grid5000', session).and_return(parent=mock("restfully resource"))
|
174
|
+
resource.load
|
175
|
+
resource.associations['parent'].should == parent
|
176
|
+
end
|
177
|
+
it "should ignore bad links" do
|
178
|
+
resource = Resource.new("uri", session = mock("session", :get => mock("restfully response", :body => {
|
179
|
+
'links' => [
|
180
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes'},
|
181
|
+
{'rel' => 'invalid_rel', 'href' => '/whatever'},
|
182
|
+
{'rel' => 'collection', 'href' => '/has/no/title'}
|
183
|
+
],
|
184
|
+
'uid' => 'rennes'
|
185
|
+
}), :logger => @logger))
|
186
|
+
resource.load
|
187
|
+
resource.associations.should be_empty
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should correctly define the functions to access links [integration test]" do
|
191
|
+
resource = Resource.new("uri", session = mock("session", :get => @response_200, :logger => @logger))
|
112
192
|
@logger.should_receive(:warn).with(/collection \/has\/no\/title has no title/)
|
113
193
|
@logger.should_receive(:warn).with(/invalid_rel is not a valid link relationship/)
|
114
|
-
Collection.should_receive(:new).
|
115
|
-
with('/sites/rennes/versions', session, 'raw' => nil, 'title' => 'versions').
|
116
|
-
and_return(versions=mock(Collection))
|
117
|
-
Collection.should_receive(:new).
|
118
|
-
with('/sites/rennes/clusters/versions/123', session, 'raw' => @raw['clusters'], 'title' => 'clusters').
|
119
|
-
and_return(clusters=mock(Collection))
|
120
|
-
Collection.should_receive(:new).
|
121
|
-
with('/sites/rennes/environments/versions/123', session, 'raw' => nil, 'title' => 'environments').
|
122
|
-
and_return(environments=mock(Collection))
|
123
|
-
Resource.should_receive(:new).
|
124
|
-
with('/versions/123', session, 'raw' => nil).
|
125
|
-
and_return(parent=mock(Resource))
|
126
|
-
Resource.should_receive(:new).
|
127
|
-
with('/sites/rennes/statuses/current', session, 'raw' => nil).
|
128
|
-
and_return(status=mock(Resource))
|
129
|
-
# associations should not exist before loading
|
130
|
-
resource.respond_to?(:clusters).should be_false
|
131
|
-
# load the resource so that associations get created
|
132
194
|
resource.load
|
133
|
-
|
134
|
-
resource.should respond_to(:clusters)
|
135
|
-
clusters.should_receive(:load).and_return(clusters)
|
136
|
-
resource.clusters.should == clusters
|
137
|
-
resource.should respond_to(:environments)
|
138
|
-
environments.should_receive(:load).and_return(environments)
|
139
|
-
resource.environments.should == environments
|
140
|
-
resource.should respond_to(:versions)
|
141
|
-
versions.should_receive(:load).and_return(versions)
|
142
|
-
resource.versions.should == versions
|
143
|
-
resource.should respond_to(:status)
|
144
|
-
status.should_receive(:load).and_return(status)
|
145
|
-
resource.status.should == status
|
146
|
-
resource.uri.should == "/sites/rennes/versions/123" # self link should override the URI attribute
|
195
|
+
resource.associations.keys.should =~ ['versions', 'clusters', 'environments', 'status', 'parent', 'version']
|
147
196
|
end
|
148
197
|
end
|
149
198
|
end
|
data/spec/restfully_spec.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe Restfully do
|
4
|
-
|
4
|
+
it "should have a default adapter" do
|
5
|
+
Restfully.adapter.should == Restfully::HTTP::Adapters::RestClientAdapter
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should allow setting other adapters" do
|
9
|
+
require 'restfully/http/adapters/patron_adapter'
|
10
|
+
Restfully.adapter = Restfully::HTTP::Adapters::PatronAdapter
|
11
|
+
Restfully.adapter.should == Restfully::HTTP::Adapters::PatronAdapter
|
12
|
+
end
|
5
13
|
end
|
data/spec/session_spec.rb
CHANGED
@@ -2,20 +2,104 @@ require File.dirname(__FILE__)+'/spec_helper'
|
|
2
2
|
|
3
3
|
include Restfully
|
4
4
|
describe Session do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
describe "initialization" do
|
6
|
+
it "should have a logger reader" do
|
7
|
+
session = Session.new('https://api.grid5000.fr')
|
8
|
+
session.should_not respond_to(:logger=)
|
9
|
+
session.should respond_to(:logger)
|
10
|
+
end
|
11
|
+
it "should have a base_uri reader" do
|
12
|
+
session = Session.new('https://api.grid5000.fr')
|
13
|
+
session.should_not respond_to(:base_uri=)
|
14
|
+
session.base_uri.should == 'https://api.grid5000.fr'
|
15
|
+
end
|
16
|
+
it "should have a root_path reader that returns the path of the root resource, relative to the base URI" do
|
17
|
+
session = Session.new('https://api.grid5000.fr/sid', 'root_path' => '/grid5000')
|
18
|
+
session.should_not respond_to(:root_path=)
|
19
|
+
session.root_path.should == '/grid5000'
|
20
|
+
end
|
21
|
+
it "should set the default root_path to /" do
|
22
|
+
session = Session.new('https://api.grid5000.fr')
|
23
|
+
session.root_path.should == '/'
|
24
|
+
end
|
25
|
+
it "should log to NullLogger by default" do
|
26
|
+
NullLogger.should_receive(:new).and_return(logger = mock(NullLogger))
|
27
|
+
session = Session.new('https://api.grid5000.fr')
|
28
|
+
session.logger.should == logger
|
29
|
+
end
|
30
|
+
it "should use the given logger" do
|
31
|
+
logger = mock("custom logger")
|
32
|
+
session = Session.new('https://api.grid5000.fr', 'logger' => logger)
|
33
|
+
session.logger.should == logger
|
34
|
+
end
|
35
|
+
it "should set a default Accept HTTP header if no default headers are given" do
|
36
|
+
session = Session.new('https://api.grid5000.fr')
|
37
|
+
session.default_headers.should == {
|
38
|
+
'Accept' => 'application/json'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
it "should use the given default headers" do
|
42
|
+
session = Session.new('https://api.grid5000.fr', :default_headers => {:accept => 'application/xml'})
|
43
|
+
session.default_headers.should == {
|
44
|
+
:accept => 'application/xml'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
it "should correctly initialize the connection" do
|
48
|
+
Restfully.adapter.should_receive(:new).with('https://api.grid5000.fr/sid', :user => 'crohr', :password => 'password').and_return(connection = mock("restfully connection"))
|
49
|
+
session = Session.new('https://api.grid5000.fr/sid', 'root_path' => '/grid5000', :user => 'crohr', :password => 'password')
|
50
|
+
session.connection.should == connection
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should initialize the root resource" do
|
54
|
+
session = Session.new('https://api.grid5000.fr', 'root_path' => '/grid5000', :user => 'crohr', :password => 'password')
|
55
|
+
session.root.should be_a Restfully::Resource
|
56
|
+
session.root.uri.to_s.should == '/grid5000'
|
57
|
+
session.root.should_not be_loaded
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should yield the loaded root resource and the session object" do
|
61
|
+
Restfully::Resource.stub!(:new).and_return(root_resource = mock(Restfully::Resource))
|
62
|
+
root_resource.should_receive(:load).and_return(root_resource)
|
63
|
+
Session.new('https://api.grid5000.fr', :root_path => '/grid5000', :user => 'crohr', :password => 'password') do |root, session|
|
64
|
+
session.root.should == root
|
65
|
+
root.should == root_resource
|
66
|
+
end
|
67
|
+
end
|
15
68
|
end
|
16
69
|
|
17
|
-
|
18
|
-
|
19
|
-
|
70
|
+
describe "Getting resources" do
|
71
|
+
before(:each) do
|
72
|
+
@session = Session.new('https://api.grid5000.fr/sid', :root_path => '/grid5000', :user => 'crohr', :password => 'password', :default_headers => {})
|
73
|
+
@request = mock("restfully http request", :uri => mock("uri"), :headers => mock("headers"))
|
74
|
+
@response = mock("restfully http response", :status => 200, :headers => mock("headers"))
|
75
|
+
end
|
76
|
+
it "should create a new Request object and pass it to the connection" do
|
77
|
+
Restfully::HTTP::Request.should_receive(:new).with(URI.parse('https://api.grid5000.fr/sid/some/path'), :headers => {:cache_control => 'max-age=0'}, :query => {}).and_return(@request)
|
78
|
+
@session.connection.should_receive(:get).with(@request).and_return(@response)
|
79
|
+
@session.get('/some/path', :headers => {:cache_control => 'max-age=0'}).should == @response
|
80
|
+
end
|
81
|
+
it "should not use the base_url if the path is a complete url" do
|
82
|
+
Restfully::HTTP::Request.should_receive(:new).with(URI.parse('http://somehost.com/some/path'), :headers => {}, :query => {}).and_return(@request)
|
83
|
+
@session.connection.should_receive(:get).with(@request).and_return(@response)
|
84
|
+
@session.get('http://somehost.com/some/path').should == @response
|
85
|
+
end
|
86
|
+
it "should add the session's default headers to the request's headers" do
|
87
|
+
Restfully::HTTP::Request.should_receive(:new).with(URI.parse('http://somehost.com/some/path'), :headers => {}, :query => {}).and_return(@request)
|
88
|
+
@session.default_headers['cache-control'] = 'max-age=0'
|
89
|
+
@request.should_receive(:add_headers).with('cache-control' => 'max-age=0')
|
90
|
+
@session.connection.should_receive(:get).with(@request).and_return(@response)
|
91
|
+
@session.get('http://somehost.com/some/path').should == @response
|
92
|
+
end
|
93
|
+
it "should raise a Restfully::HTTP::ClientError error on 4xx errors" do
|
94
|
+
Restfully::HTTP::Request.should_receive(:new).with(URI.parse('http://somehost.com/some/path'), :headers => {}, :query => {}).and_return(@request)
|
95
|
+
@session.connection.should_receive(:get).with(@request).and_return(response = mock("404 response", :status => 404, :body => {'code' => 404, 'message' => 'The requested resource cannot be found.', 'title' => 'Not Found'}, :headers => mock("headers")))
|
96
|
+
lambda{ @session.get('http://somehost.com/some/path') }.should raise_error(Restfully::HTTP::ClientError, "404 Not Found. The requested resource cannot be found.")
|
97
|
+
end
|
98
|
+
it "should raise a Restfully::HTTP::ServerError error on 4xx errors" do
|
99
|
+
Restfully::HTTP::Request.should_receive(:new).with(URI.parse('http://somehost.com/some/path'), :headers => {}, :query => {}).and_return(@request)
|
100
|
+
@session.connection.should_receive(:get).with(@request).and_return(response = mock("404 response", :status => 500, :body => {'code' => 500, 'message' => 'Something went wrong.', 'title' => 'Internal Server Error'}, :headers => mock("headers")))
|
101
|
+
lambda{ @session.get('http://somehost.com/some/path') }.should raise_error(Restfully::HTTP::ServerError, "500 Internal Server Error. Something went wrong.")
|
102
|
+
end
|
20
103
|
end
|
104
|
+
|
21
105
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
3
|
require 'restfully'
|
5
4
|
require 'spec'
|
6
5
|
require 'spec/autorun'
|
7
6
|
|
7
|
+
def fixture(filename)
|
8
|
+
File.read(File.join(File.dirname(__FILE__), "fixtures", filename))
|
9
|
+
end
|
8
10
|
|
9
11
|
Spec::Runner.configure do |config|
|
10
12
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crohr-restfully
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Rohr
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-17 00:00:00 -07:00
|
13
13
|
default_executable: restfully
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
23
|
+
version: "1.0"
|
24
24
|
version:
|
25
25
|
description: Experimental code for auto-generation of wrappers on top of RESTful APIs that follow HATEOAS principles and provide OPTIONS methods and/or Allow headers.
|
26
26
|
email: cyril.rohr@gmail.com
|
@@ -37,12 +37,22 @@ files:
|
|
37
37
|
- LICENSE
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
|
+
- TODO.rdoc
|
40
41
|
- VERSION
|
41
42
|
- bin/restfully
|
42
43
|
- examples/grid5000.rb
|
43
44
|
- lib/restfully.rb
|
44
45
|
- lib/restfully/collection.rb
|
46
|
+
- lib/restfully/error.rb
|
45
47
|
- lib/restfully/extensions.rb
|
48
|
+
- lib/restfully/http.rb
|
49
|
+
- lib/restfully/http/adapters/abstract_adapter.rb
|
50
|
+
- lib/restfully/http/adapters/patron_adapter.rb
|
51
|
+
- lib/restfully/http/adapters/rest_client_adapter.rb
|
52
|
+
- lib/restfully/http/error.rb
|
53
|
+
- lib/restfully/http/headers.rb
|
54
|
+
- lib/restfully/http/request.rb
|
55
|
+
- lib/restfully/http/response.rb
|
46
56
|
- lib/restfully/link.rb
|
47
57
|
- lib/restfully/parsing.rb
|
48
58
|
- lib/restfully/resource.rb
|
@@ -51,7 +61,14 @@ files:
|
|
51
61
|
- lib/restfully/special_hash.rb
|
52
62
|
- restfully.gemspec
|
53
63
|
- spec/collection_spec.rb
|
64
|
+
- spec/fixtures/grid5000-sites.json
|
65
|
+
- spec/http/error_spec.rb
|
66
|
+
- spec/http/headers_spec.rb
|
67
|
+
- spec/http/request_spec.rb
|
68
|
+
- spec/http/response_spec.rb
|
69
|
+
- spec/http/rest_client_adapter_spec.rb
|
54
70
|
- spec/link_spec.rb
|
71
|
+
- spec/parsing_spec.rb
|
55
72
|
- spec/resource_spec.rb
|
56
73
|
- spec/restfully_spec.rb
|
57
74
|
- spec/session_spec.rb
|
@@ -78,14 +95,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
95
|
version:
|
79
96
|
requirements: []
|
80
97
|
|
81
|
-
rubyforge_project:
|
98
|
+
rubyforge_project: restfully
|
82
99
|
rubygems_version: 1.3.5
|
83
100
|
signing_key:
|
84
101
|
specification_version: 3
|
85
102
|
summary: Experimental code for auto-generation of wrappers on top of RESTful APIs that follow some specific conventions.
|
86
103
|
test_files:
|
87
104
|
- spec/collection_spec.rb
|
105
|
+
- spec/http/error_spec.rb
|
106
|
+
- spec/http/headers_spec.rb
|
107
|
+
- spec/http/request_spec.rb
|
108
|
+
- spec/http/response_spec.rb
|
109
|
+
- spec/http/rest_client_adapter_spec.rb
|
88
110
|
- spec/link_spec.rb
|
111
|
+
- spec/parsing_spec.rb
|
89
112
|
- spec/resource_spec.rb
|
90
113
|
- spec/restfully_spec.rb
|
91
114
|
- spec/session_spec.rb
|