rack-test-rest 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -61,6 +61,8 @@ to create either the URI for creating/indexing resources or the URI for a partic
61
61
  :root_uri + '/' + :resource + :extension
62
62
  :root_uri + '/' + :resource + '/' + params[:id].to_s + :extension
63
63
 
64
+ Currently JSON is the only supported response Content-Type.
65
+
64
66
  ## `create_resource(params={})`
65
67
 
66
68
  Performs a POST to with any specified parameters to `:root_uri/:resource:extension`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -6,6 +6,25 @@ module Rack
6
6
  "#{@rack_test_rest[:root_uri]}/#{@rack_test_rest[:resource]}"
7
7
  end
8
8
 
9
+ def handle_error_code(code)
10
+ assert_equal(code, last_response.status)
11
+
12
+ if @rack_test_rest[:debug]
13
+ puts "Status: #{last_response.status}" if @rack_test_rest[:debug]
14
+ puts "Headers:"
15
+ puts last_response.headers.inspect
16
+ puts "Body: #{last_response.body}" if @rack_test_rest[:debug]
17
+ end
18
+
19
+ assert_equal 'application/json', last_response.headers['Content-Type']
20
+
21
+ if last_response.headers['Content-Length'].to_i > 0
22
+ JSON.parse(last_response.body)
23
+ else
24
+ nil
25
+ end
26
+ end
27
+
9
28
  def create_resource(params={})
10
29
  expected_code = params[:code]
11
30
  params.delete :code
@@ -13,17 +32,18 @@ module Rack
13
32
  puts "Posting to: '#{resource_uri}#{@rack_test_rest[:extension]}'" if @rack_test_rest[:debug]
14
33
  post "#{resource_uri}#{@rack_test_rest[:extension]}", params
15
34
 
16
- if expected_code
17
- assert_equal(expected_code, last_response.status)
18
- else
19
- if @rack_test_rest[:debug]
20
- puts "#{last_response.status}: #{last_response.body}"
21
- puts last_response.original_headers["Location"]
22
- end
23
- assert_equal(201, last_response.status)
24
- if @rack_test_rest[:location]
25
- assert last_response.original_headers["Location"] =~ @rack_test_rest[:location]
26
- end
35
+ return handle_error_code(expected_code) if expected_code
36
+
37
+ if @rack_test_rest[:debug]
38
+ puts "#{last_response.status}: #{last_response.body}"
39
+ puts last_response.original_headers["Location"]
40
+ end
41
+
42
+ assert_equal(201, last_response.status)
43
+ assert_equal 'application/json', last_response.headers['Content-Type']
44
+
45
+ if @rack_test_rest[:location]
46
+ assert last_response.original_headers["Location"] =~ @rack_test_rest[:location]
27
47
  end
28
48
 
29
49
  last_response.original_headers["Location"]
@@ -44,18 +64,17 @@ module Rack
44
64
  puts "GET #{uri} #{params}" if @rack_test_rest[:debug]
45
65
  get uri, params
46
66
 
67
+ return handle_error_code(expected_code) if expected_code
68
+
47
69
  if @rack_test_rest[:debug]
48
70
  puts "Code: #{last_response.status}"
49
71
  puts "Body: #{last_response.body}"
50
72
  end
51
73
 
52
- if expected_code
53
- assert_equal(expected_code, last_response.status)
54
- return nil
55
- else
56
- assert_equal(200, last_response.status)
57
- return JSON.parse(last_response.body)
58
- end
74
+ assert_equal 'application/json', last_response.headers['Content-Type']
75
+ assert_equal(200, last_response.status)
76
+
77
+ JSON.parse(last_response.body)
59
78
  end
60
79
 
61
80
  def update_resource(params={})
@@ -69,23 +88,19 @@ module Rack
69
88
 
70
89
  put "#{resource_uri}/#{id}#{@rack_test_rest[:extension]}", params
71
90
 
91
+ return handle_error_code(expected_code) if expected_code
92
+
72
93
  puts "#{last_response.status}: #{last_response.body}" if @rack_test_rest[:debug]
73
94
 
74
- if expected_code
75
- assert_equal(expected_code, last_response.status)
76
- else
77
- assert_equal(204, last_response.status)
78
- end
95
+ assert_equal(204, last_response.status)
79
96
  end
80
97
 
81
98
  def delete_resource(params={})
82
99
  delete "#{resource_uri}/#{params[:id]}#{@rack_test_rest[:extension]}"
83
100
 
84
- if params[:code]
85
- assert_equal(params[:code], last_response.status)
86
- else
87
- assert_equal(204, last_response.status)
88
- end
101
+ return handle_error_code(params[:code]) if params[:code]
102
+
103
+ assert_equal(204, last_response.status)
89
104
  end
90
105
 
91
106
  def paginate_resource(params={})
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{rack-test-rest}
8
- s.version = "0.3.0"
7
+ s.name = "rack-test-rest"
8
+ s.version = "0.4.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-10-02}
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
- s.email = %q{joe@ruscio.org}
12
+ s.date = "2011-10-20"
13
+ s.description = "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
+ s.email = "joe@ruscio.org"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.md"
@@ -29,11 +29,11 @@ Gem::Specification.new do |s|
29
29
  "test/helper.rb",
30
30
  "test/test_rack-test-rest.rb"
31
31
  ]
32
- s.homepage = %q{http://github.com/josephruscio/rack-test-rest}
32
+ s.homepage = "http://github.com/josephruscio/rack-test-rest"
33
33
  s.licenses = ["MIT"]
34
34
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.6.2}
36
- s.summary = %q{Abstractions for testing RESTful API's with rack-test and Test::Unit.}
35
+ s.rubygems_version = "1.8.10"
36
+ s.summary = "Abstractions for testing RESTful API's with rack-test and Test::Unit."
37
37
  s.test_files = [
38
38
  "test/helper.rb",
39
39
  "test/test_rack-test-rest.rb"
metadata CHANGED
@@ -1,93 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-test-rest
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Joseph Ruscio
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-02 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- type: :development
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
12
+ date: 2011-10-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
32
15
  name: shoulda
33
- version_requirements: *id001
34
- prerelease: false
35
- - !ruby/object:Gem::Dependency
16
+ requirement: &2163619080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
36
22
  type: :development
37
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: *2163619080
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2163618380 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
29
+ requirements:
40
30
  - - ~>
41
- - !ruby/object:Gem::Version
42
- hash: 23
43
- segments:
44
- - 1
45
- - 0
46
- - 0
31
+ - !ruby/object:Gem::Version
47
32
  version: 1.0.0
48
- name: bundler
49
- version_requirements: *id002
50
- prerelease: false
51
- - !ruby/object:Gem::Dependency
52
33
  type: :development
53
- requirement: &id003 !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ version_requirements: *2163618380
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &2163617640 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
40
+ requirements:
56
41
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 7
59
- segments:
60
- - 1
61
- - 5
62
- - 2
42
+ - !ruby/object:Gem::Version
63
43
  version: 1.5.2
64
- name: jeweler
65
- version_requirements: *id003
66
- prerelease: false
67
- - !ruby/object:Gem::Dependency
68
44
  type: :development
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
45
+ prerelease: false
46
+ version_requirements: *2163617640
47
+ - !ruby/object:Gem::Dependency
78
48
  name: rcov
79
- version_requirements: *id004
49
+ requirement: &2163617040 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
80
56
  prerelease: false
81
- description: 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.
57
+ version_requirements: *2163617040
58
+ description: rack-test-rest is an extension to rack-test that when combined with Test::Unit
59
+ simplifies the process of unit testing properly designed RESTful API's.
82
60
  email: joe@ruscio.org
83
61
  executables: []
84
-
85
62
  extensions: []
86
-
87
- extra_rdoc_files:
63
+ extra_rdoc_files:
88
64
  - LICENSE.txt
89
65
  - README.md
90
- files:
66
+ files:
91
67
  - .document
92
68
  - Gemfile
93
69
  - Gemfile.lock
@@ -99,40 +75,34 @@ files:
99
75
  - rack-test-rest.gemspec
100
76
  - test/helper.rb
101
77
  - test/test_rack-test-rest.rb
102
- has_rdoc: true
103
78
  homepage: http://github.com/josephruscio/rack-test-rest
104
- licenses:
79
+ licenses:
105
80
  - MIT
106
81
  post_install_message:
107
82
  rdoc_options: []
108
-
109
- require_paths:
83
+ require_paths:
110
84
  - lib
111
- required_ruby_version: !ruby/object:Gem::Requirement
85
+ required_ruby_version: !ruby/object:Gem::Requirement
112
86
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ segments:
118
92
  - 0
119
- version: "0"
120
- required_rubygems_version: !ruby/object:Gem::Requirement
93
+ hash: -210201095594734930
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
95
  none: false
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
127
- - 0
128
- version: "0"
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
129
100
  requirements: []
130
-
131
101
  rubyforge_project:
132
- rubygems_version: 1.6.2
102
+ rubygems_version: 1.8.10
133
103
  signing_key:
134
104
  specification_version: 3
135
105
  summary: Abstractions for testing RESTful API's with rack-test and Test::Unit.
136
- test_files:
106
+ test_files:
137
107
  - test/helper.rb
138
108
  - test/test_rack-test-rest.rb