rack-test-rest 0.2.0 → 0.3.0
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.md +9 -8
- data/VERSION +1 -1
- data/lib/rack-test-rest.rb +6 -6
- data/rack-test-rest.gemspec +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -21,7 +21,8 @@ that is testing a specific resource e.g.:
|
|
21
21
|
@rack_test_rest = {
|
22
22
|
#:debug => true,
|
23
23
|
:root_uri => "/v1/metrics",
|
24
|
-
:resource => "gauges"
|
24
|
+
:resource => "gauges",
|
25
|
+
:extension => ".json" #other possibilities ".xml", "_json",".html", etc
|
25
26
|
}
|
26
27
|
end
|
27
28
|
|
@@ -57,12 +58,12 @@ required to test any particular resource. You need only specify `:root_uri` and
|
|
57
58
|
in your test setup (through the `@rack_test_rest` instance variable). These are combined
|
58
59
|
to create either the URI for creating/indexing resources or the URI for a particular resource:
|
59
60
|
|
60
|
-
:root_uri + '/' + :resource +
|
61
|
-
:root_uri + '/' + :resource + '/' + params[:id].to_s +
|
61
|
+
:root_uri + '/' + :resource + :extension
|
62
|
+
:root_uri + '/' + :resource + '/' + params[:id].to_s + :extension
|
62
63
|
|
63
64
|
## `create_resource(params={})`
|
64
65
|
|
65
|
-
Performs a POST to with any specified parameters to `:root_uri/:resource
|
66
|
+
Performs a POST to with any specified parameters to `:root_uri/:resource:extension`
|
66
67
|
and ensures that it returns `201`. Returns the string value found in the response's
|
67
68
|
`Location` header.
|
68
69
|
|
@@ -70,18 +71,18 @@ and ensures that it returns `201`. Returns the string value found in the respons
|
|
70
71
|
|
71
72
|
Performs a GET with any specified parameters and validates that it returns `200`.
|
72
73
|
If `:id` is specified the GET is performed against a singular resource i.e.
|
73
|
-
`:root_uri/:resource/:id
|
74
|
-
as an index operation against `:root_uri/:resource
|
74
|
+
`:root_uri/:resource/:id:extension`. In the absence of `:id` the GET is performed
|
75
|
+
as an index operation against `:root_uri/:resource:extension`. Returns parsed
|
75
76
|
JSON of the response body on a `200`.
|
76
77
|
|
77
78
|
## `update_resource(params={})`
|
78
79
|
|
79
|
-
Requires an :id parameter. Performs a PUT against `:root_uri/:resource/:id
|
80
|
+
Requires an :id parameter. Performs a PUT against `:root_uri/:resource/:id:extension`
|
80
81
|
with any other specified parameters and asserts that it returns `204`.
|
81
82
|
|
82
83
|
## `delete_resource(params={})`
|
83
84
|
|
84
|
-
Requires an :id parameter. Performs a DELETE against `:root_uri/:resource/:id
|
85
|
+
Requires an :id parameter. Performs a DELETE against `:root_uri/:resource/:id:extension`
|
85
86
|
and asserts that it returns `204`.
|
86
87
|
|
87
88
|
## Testing invalid input
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/rack-test-rest.rb
CHANGED
@@ -10,8 +10,8 @@ module Rack
|
|
10
10
|
expected_code = params[:code]
|
11
11
|
params.delete :code
|
12
12
|
|
13
|
-
puts "Posting to: '#{resource_uri}
|
14
|
-
post "#{resource_uri}
|
13
|
+
puts "Posting to: '#{resource_uri}#{@rack_test_rest[:extension]}'" if @rack_test_rest[:debug]
|
14
|
+
post "#{resource_uri}#{@rack_test_rest[:extension]}", params
|
15
15
|
|
16
16
|
if expected_code
|
17
17
|
assert_equal(expected_code, last_response.status)
|
@@ -36,9 +36,9 @@ module Rack
|
|
36
36
|
if params[:id]
|
37
37
|
id = params[:id]
|
38
38
|
params.delete(:id)
|
39
|
-
uri = resource_uri
|
39
|
+
uri = "#{resource_uri}/#{id}#{@rack_test_rest[:extension]}"
|
40
40
|
else
|
41
|
-
uri = resource_uri
|
41
|
+
uri = "#{resource_uri}#{@rack_test_rest[:extension]}"
|
42
42
|
end
|
43
43
|
|
44
44
|
puts "GET #{uri} #{params}" if @rack_test_rest[:debug]
|
@@ -67,7 +67,7 @@ module Rack
|
|
67
67
|
|
68
68
|
puts "Attempting to update #{id} with #{params}" if @rack_test_rest[:debug]
|
69
69
|
|
70
|
-
put "#{resource_uri}/#{id}
|
70
|
+
put "#{resource_uri}/#{id}#{@rack_test_rest[:extension]}", params
|
71
71
|
|
72
72
|
puts "#{last_response.status}: #{last_response.body}" if @rack_test_rest[:debug]
|
73
73
|
|
@@ -79,7 +79,7 @@ module Rack
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def delete_resource(params={})
|
82
|
-
delete "#{resource_uri}/#{params[:id]}
|
82
|
+
delete "#{resource_uri}/#{params[:id]}#{@rack_test_rest[:extension]}"
|
83
83
|
|
84
84
|
if params[:code]
|
85
85
|
assert_equal(params[:code], last_response.status)
|
data/rack-test-rest.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-test-rest}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joseph Ruscio"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-10-02}
|
13
13
|
s.description = %q{rack-test-rest is an extension to rack-test that when combined with Test::Unit simplifies the process of unit testing properly designed RESTful API's.}
|
14
14
|
s.email = %q{joe@ruscio.org}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-test-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joseph Ruscio
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-02 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|