assert-response 1.0.0 → 1.1.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/Gemfile +1 -0
- data/README.md +11 -2
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/assert-response.rb +186 -25
- data/test/test_assert-response.rb +157 -0
- metadata +37 -15
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -32,6 +32,7 @@ or in rvm:
|
|
32
32
|
|
33
33
|
Examples
|
34
34
|
--------
|
35
|
+
|
35
36
|
require 'minitest'
|
36
37
|
require 'rack/test'
|
37
38
|
require 'assert-reponse'
|
@@ -45,6 +46,7 @@ Examples
|
|
45
46
|
_(for usage without the inclusion of Rack::Test::Methods or with Test::Unit, see AssertResponse::Methods)_
|
46
47
|
|
47
48
|
And then in your test something like this:
|
49
|
+
|
48
50
|
get '/myroute'
|
49
51
|
assert_response_html 'my body'
|
50
52
|
|
@@ -58,10 +60,12 @@ This will
|
|
58
60
|
|
59
61
|
But you may also want to...
|
60
62
|
check just the mime type:
|
63
|
+
|
61
64
|
get '/myroute'
|
62
65
|
assert_response_is_html
|
63
66
|
|
64
67
|
check for a 404 page:
|
68
|
+
|
65
69
|
get '/myroute'
|
66
70
|
assert_response_not_found_html "Not found!"
|
67
71
|
|
@@ -95,9 +99,9 @@ There is some additional sugar like
|
|
95
99
|
assert_response_not_found
|
96
100
|
assert_response_ok
|
97
101
|
|
98
|
-
Everything after
|
102
|
+
Everything after *assert\_response\_* is the called method of _AssertResponse_, look them up in the documentation.
|
99
103
|
|
100
|
-
When using the
|
104
|
+
When using the *assert\_response\_* methods always the *last_response* object is checked.
|
101
105
|
|
102
106
|
If you want to check a saved response instead, you may use the little DSL
|
103
107
|
|
@@ -111,6 +115,11 @@ If you want to check a saved response instead, you may use the little DSL
|
|
111
115
|
|
112
116
|
Now inside the code block you may use the methods of _AssertResponse_ (but without the *assert\_response\_* prefixes).
|
113
117
|
|
118
|
+
TODO
|
119
|
+
----
|
120
|
+
|
121
|
+
Maybe add some sugar for cookie testing.
|
122
|
+
|
114
123
|
|
115
124
|
Contributing to assert-response
|
116
125
|
-------------------------------
|
data/Rakefile
CHANGED
@@ -20,6 +20,7 @@ Jeweler::Tasks.new do |gem|
|
|
20
20
|
gem.email = "Base64.decode64('bGludXhAbWFyY3JlbmVhcm5zLmRl\n')"
|
21
21
|
gem.authors = ["Marc Rene Arns"]
|
22
22
|
gem.add_runtime_dependency 'rack-test'
|
23
|
+
gem.add_runtime_dependency 'json'
|
23
24
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
24
25
|
end
|
25
26
|
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/assert-response.rb
CHANGED
@@ -1,7 +1,71 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
class AssertResponse
|
4
|
+
|
5
|
+
# to allow checking against a parsed json object
|
6
|
+
# the code is instance_exec'd in the context of this
|
7
|
+
# object. you may call the assert- methods here (even without assert-
|
8
|
+
# prefix and you have the json object by calling the json method
|
9
|
+
class AssertJSON
|
10
|
+
def initialize(test_obj, json_string)
|
11
|
+
@test_obj = test_obj
|
12
|
+
@json_obj = JSON.parse(json_string)
|
13
|
+
end
|
14
|
+
|
15
|
+
def json
|
16
|
+
@json_obj
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(meth, *args, &code)
|
20
|
+
if @test_obj.respond_to? meth
|
21
|
+
@test_obj.send meth, *args, &code
|
22
|
+
elsif @test_obj.respond_to? :"assert_#{meth}"
|
23
|
+
@test_obj.send :"assert_#{meth}", *args, &code
|
24
|
+
else
|
25
|
+
@test_obj.send :method_missing, *args.unshift(meth), &code
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
2
29
|
|
3
30
|
# error class, raised when a 404 status but another status was expected
|
4
|
-
class
|
31
|
+
class HttpError < Exception ; end
|
32
|
+
class Status404 < HttpError ; end
|
33
|
+
|
34
|
+
# Hash with names for the http 1.1 status codes
|
35
|
+
HTTP_STATUS_CODES = {
|
36
|
+
:ok => 200,
|
37
|
+
:not_found => 404,
|
38
|
+
:created => 201,
|
39
|
+
:bad_request => 400,
|
40
|
+
:unauthorized => 401,
|
41
|
+
:forbidden => 403,
|
42
|
+
:timeout => 408,
|
43
|
+
:gateway_timeout => 504,
|
44
|
+
:bad_gateway => 502,
|
45
|
+
:conflict => 409,
|
46
|
+
:gone => 410,
|
47
|
+
:too_many_requests => 429,
|
48
|
+
:upgrade_required => 426,
|
49
|
+
:teapot => 418,
|
50
|
+
:no_response => 444,
|
51
|
+
:bandwidth_limit_exceeded => 509,
|
52
|
+
:maintenance => 503,
|
53
|
+
:insufficient_storage => 507,
|
54
|
+
:http_version_not_supported => 505,
|
55
|
+
:payment_required => 402,
|
56
|
+
:not_modified => 304,
|
57
|
+
:see_other => 303,
|
58
|
+
:found => 302,
|
59
|
+
:moved => 301,
|
60
|
+
:reset => 205,
|
61
|
+
:reload => 205,
|
62
|
+
:no_content => 204,
|
63
|
+
:too_large => 413,
|
64
|
+
:uri_too_long => 414,
|
65
|
+
:unsupported_media_type => 415,
|
66
|
+
:not_implemented => 501,
|
67
|
+
:error => 500
|
68
|
+
}
|
5
69
|
|
6
70
|
# Hash to collection available content-types (prefilled with the Rack::Mime::MIME_TYPES)
|
7
71
|
#
|
@@ -24,13 +88,23 @@ class AssertResponse
|
|
24
88
|
# add content_type 'text/plain' as :text
|
25
89
|
AssertResponse.add_content_type :text, 'text/plain'
|
26
90
|
|
91
|
+
# Adds custom http code to
|
92
|
+
# {AssertResponse::HTTP_STATUS_CODES}. We would then have all the test methods for the status code
|
93
|
+
# @param [Symbol] name name of the http status code
|
94
|
+
# @param [Integer] code code number (eg. 404)
|
95
|
+
def AssertResponse.add_http_status_code(name, code)
|
96
|
+
raise "invalid code" unless code =~ /^[1-9][0-9]{2}$/
|
97
|
+
HTTP_STATUS_CODES.update(name => code)
|
98
|
+
end
|
99
|
+
|
27
100
|
# Creates a new {AssertResponse} Object. Usually you will want to +instance_exec+ some code on it.
|
28
101
|
#
|
29
102
|
# @param [Object] delegate_to the test object that has all the +assert_equal+, +assert_match+ and +assert+ methods that we need
|
30
103
|
# @param [MockResponse, Response] response the response object that is checked
|
31
|
-
def initialize(delegate_to, response, &code)
|
104
|
+
def initialize(delegate_to, response, request, &code)
|
32
105
|
@delegate_to = delegate_to
|
33
106
|
@response = response
|
107
|
+
@request = request
|
34
108
|
@error = nil
|
35
109
|
check_for_error()
|
36
110
|
end
|
@@ -50,43 +124,105 @@ class AssertResponse
|
|
50
124
|
when /^not_found_(.+)$/ # not_found_[content_type] methods
|
51
125
|
if ctype = CONTENT_TYPES[$1.to_sym]
|
52
126
|
content_type ctype
|
53
|
-
return body(args.first,
|
127
|
+
return body(args.first, :not_found)
|
54
128
|
end
|
55
129
|
else
|
56
|
-
if ctype = CONTENT_TYPES[meth] # [content_type] methods
|
57
|
-
ok()
|
130
|
+
if ctype = CONTENT_TYPES[meth] # [content_type] methods
|
58
131
|
content_type ctype
|
59
|
-
return body(args
|
132
|
+
return body(*args)
|
133
|
+
elsif HTTP_STATUS_CODES[meth]
|
134
|
+
return status HTTP_STATUS_CODES[meth]
|
60
135
|
end
|
61
136
|
end
|
62
137
|
@delegate_to.send meth, *args, &code
|
63
138
|
end
|
64
139
|
|
65
|
-
# Checks if status is
|
140
|
+
# Checks if status is some of the ok-codes.
|
66
141
|
def ok()
|
67
|
-
status
|
142
|
+
status /^20[0-9]$/
|
143
|
+
end
|
144
|
+
|
145
|
+
# shortcut to the path of the last request
|
146
|
+
def path_info
|
147
|
+
@request.env['PATH_INFO']
|
148
|
+
end
|
149
|
+
|
150
|
+
# shortcut to the url of the last request
|
151
|
+
def url
|
152
|
+
@request.url
|
153
|
+
end
|
154
|
+
|
155
|
+
# shortcut to the query string of the last request
|
156
|
+
def query_string
|
157
|
+
@request.env['QUERY_STRING']
|
158
|
+
end
|
159
|
+
|
160
|
+
# this method checks for content_type json and then it has 2 modes
|
161
|
+
# if no code block is given, it acts as "body"
|
162
|
+
# if a code block is given, arg1 is the status and arg2 is ignored
|
163
|
+
# the code is executed in the context of a AssertJSON object, where
|
164
|
+
# you can use the usual assert- methods (even without assert prefix)
|
165
|
+
# and the json method gives you the parsed json object to test against
|
166
|
+
def json(arg1=nil, arg2=nil, &code)
|
167
|
+
content_type CONTENT_TYPES[:json]
|
168
|
+
if code
|
169
|
+
status arg1
|
170
|
+
file, line, rest = caller[0].split(':', 3)
|
171
|
+
AssertJSON.new(@delegate_to, @response.body).instance_exec(file, line.to_i, &code)
|
172
|
+
elsif arg1
|
173
|
+
body arg1, arg2
|
174
|
+
end
|
68
175
|
end
|
69
176
|
|
70
177
|
# Checks if the status is +status+. For status other then 5xx and error is raised if the response has an error.
|
71
178
|
# For status other than 404 an error Status404 is thrown if response status is 404
|
179
|
+
# If we do not check for a 4xx or 5xx code an StatusError is raised if such a code is found and the body is given as error message
|
72
180
|
#
|
73
|
-
# @params [Integer] status the expected status
|
181
|
+
# @params [Integer, Regexp, Symbol] status the expected status (if it's a symbol it is looked up in HTTP_STATUS_CODES
|
74
182
|
def status(status)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
183
|
+
return ok() if status.nil?
|
184
|
+
if status.is_a?(Symbol)
|
185
|
+
raise "unknown status #{status}" unless HTTP_STATUS_CODES[status]
|
186
|
+
status = HTTP_STATUS_CODES[status]
|
187
|
+
end
|
188
|
+
look_for_5xx = case status
|
189
|
+
when Regexp
|
190
|
+
((50.to_s =~ status) || (51.to_s =~ status))? true : false
|
191
|
+
else
|
192
|
+
(status.to_s =~ /^5/) ? true : false
|
193
|
+
end
|
194
|
+
look_for_404 = case status
|
195
|
+
when Regexp
|
196
|
+
(404.to_s =~ status) ? true : false
|
197
|
+
else
|
198
|
+
(status.to_s == "404") ? true : false
|
199
|
+
end
|
200
|
+
look_for_4xx = case status
|
201
|
+
when Regexp
|
202
|
+
((40.to_s =~ status) || (41.to_s =~ status))? true : false
|
203
|
+
else
|
204
|
+
(status.to_s =~ /^4/) ? true : false
|
205
|
+
end
|
206
|
+
raise_error() unless look_for_5xx or @response.errors.empty?
|
207
|
+
Kernel.raise(Status404, "(#{url}) not found") unless look_for_404 or @response.status != 404
|
208
|
+
|
209
|
+
case status
|
210
|
+
when Regexp
|
211
|
+
raise_http_error() if @response.status.to_s =~ /^5/ and !look_for_5xx
|
212
|
+
raise_http_error() if @response.status.to_s =~ /^4/ and !look_for_4xx
|
213
|
+
assert_match(status, @response.status.to_s)
|
214
|
+
else
|
215
|
+
raise_http_error() if @response.status.to_s =~ /^5/ and status.to_s !~ /^5/
|
216
|
+
raise_http_error() if @response.status.to_s =~ /^4/ and status.to_s !~ /^4/
|
217
|
+
assert_equal(status, @response.status)
|
218
|
+
end
|
83
219
|
end
|
84
220
|
|
85
221
|
# Checks if the status is 302, and the header "Location" matches the +pattern+
|
86
222
|
#
|
87
223
|
# @param [String,Regexp] pattern the pattern to match against.
|
88
224
|
def redirect(pattern)
|
89
|
-
status
|
225
|
+
status /^30(2|3|7)$/
|
90
226
|
header 'Location', pattern
|
91
227
|
end
|
92
228
|
|
@@ -97,8 +233,10 @@ class AssertResponse
|
|
97
233
|
def header(key, pattern=:exists)
|
98
234
|
if pattern == :exists
|
99
235
|
assert !@response.headers[key].to_s.empty?, "Header '#{key}' not found"
|
100
|
-
|
236
|
+
elsif pattern.is_a? Regexp
|
101
237
|
assert_match normalize_pattern(pattern), @response.headers[key].to_s
|
238
|
+
else
|
239
|
+
assert_equal pattern.to_s, @response.headers[key].to_s
|
102
240
|
end
|
103
241
|
end
|
104
242
|
|
@@ -106,14 +244,14 @@ class AssertResponse
|
|
106
244
|
#
|
107
245
|
# @param [String,Regexp] pattern the pattern to match against.
|
108
246
|
def content_type(pattern)
|
109
|
-
header 'Content-Type', pattern
|
247
|
+
header 'Content-Type', normalize_pattern(pattern)
|
110
248
|
end
|
111
249
|
|
112
250
|
# Check if body matches +pattern+ and status is +status+.
|
113
251
|
#
|
114
252
|
# @param [String,Regexp] pattern the pattern to match against.
|
115
253
|
# @params [Integer] status the expected status (default 200, see {#ok})
|
116
|
-
def body(pattern, status=
|
254
|
+
def body(pattern, status=nil)
|
117
255
|
status(status)
|
118
256
|
assert_match normalize_pattern(pattern), @response.body
|
119
257
|
end
|
@@ -128,10 +266,28 @@ class AssertResponse
|
|
128
266
|
assert !@error.nil?
|
129
267
|
end
|
130
268
|
|
269
|
+
# redirect to get
|
270
|
+
def see_other(pattern)
|
271
|
+
status 303
|
272
|
+
header 'Location', pattern
|
273
|
+
end
|
274
|
+
|
275
|
+
# temporary move
|
276
|
+
def found(pattern)
|
277
|
+
status 302
|
278
|
+
header 'Location', pattern
|
279
|
+
end
|
280
|
+
|
281
|
+
# permanent move
|
282
|
+
def moved(pattern)
|
283
|
+
status 301
|
284
|
+
header 'Location', pattern
|
285
|
+
end
|
286
|
+
|
131
287
|
private
|
132
288
|
|
133
289
|
def normalize_pattern(pattern)
|
134
|
-
pattern.is_a?(Regexp) ? pattern : /#{Regexp.escape(pattern.to_s)}/
|
290
|
+
pattern.is_a?(Regexp) ? pattern : /#{Regexp.escape(pattern.to_s)}/i
|
135
291
|
end
|
136
292
|
|
137
293
|
def check_for_error
|
@@ -139,6 +295,7 @@ class AssertResponse
|
|
139
295
|
end
|
140
296
|
|
141
297
|
def normalize_error
|
298
|
+
#p [:l, last_request] #@response
|
142
299
|
message, backtrace = @response.errors.split "\n", 2
|
143
300
|
backtrace = backtrace.split
|
144
301
|
err_klass, message = message.split '-', 2
|
@@ -151,6 +308,10 @@ class AssertResponse
|
|
151
308
|
Kernel.raise @error
|
152
309
|
end
|
153
310
|
|
311
|
+
def raise_http_error()
|
312
|
+
raise HttpError, "#{@response.status} (#{url}) #{@response.body}"
|
313
|
+
end
|
314
|
+
|
154
315
|
# these methods are included in Rack::Test::Methods to be used in a Test Class
|
155
316
|
#
|
156
317
|
# call assert_response with a code block to use the DSL (methods from {AssertResponse})
|
@@ -237,7 +398,7 @@ class AssertResponse
|
|
237
398
|
# @see AssertResponse
|
238
399
|
def method_missing(meth, *args, &code)
|
239
400
|
if meth.to_s =~ /^assert_response_(.+)$/
|
240
|
-
AssertResponse.new(self, last_response).send($1.to_sym, *args)
|
401
|
+
AssertResponse.new(self, last_response, last_request).send($1.to_sym, *args, &code)
|
241
402
|
else
|
242
403
|
super
|
243
404
|
end
|
@@ -245,9 +406,9 @@ class AssertResponse
|
|
245
406
|
|
246
407
|
# creates an {AssertResponse} Object and +instance_exec+ the code (DSL) in it
|
247
408
|
# @see AssertResponse
|
248
|
-
def assert_response(response=last_response, &code)
|
409
|
+
def assert_response(response=last_response, request=last_request, &code)
|
249
410
|
file, line, rest = caller[0].split(':', 3)
|
250
|
-
AssertResponse.new(self, response).instance_exec(file, line.to_i, &code)
|
411
|
+
AssertResponse.new(self, response, request).instance_exec(file, line.to_i, &code)
|
251
412
|
end
|
252
413
|
end
|
253
414
|
end
|
@@ -2,6 +2,8 @@ require 'backports' if RUBY_VERSION =~ /1.8/
|
|
2
2
|
require_relative "helper.rb"
|
3
3
|
require_relative File.join("..", "lib", "assert-response.rb")
|
4
4
|
|
5
|
+
ENV['RACK_ENV'] = 'test'
|
6
|
+
|
5
7
|
include Rack::Test::Methods
|
6
8
|
|
7
9
|
def handle_exception(env)
|
@@ -32,6 +34,13 @@ def app
|
|
32
34
|
when '/json'
|
33
35
|
headers['Content-Type'] = 'application/json'
|
34
36
|
body = '{"response":"ok"}'
|
37
|
+
when '/create_with_json'
|
38
|
+
headers['Content-Type'] = 'application/json'
|
39
|
+
body = '{"id":"new_id"}'
|
40
|
+
status = 201
|
41
|
+
when '/bad_request'
|
42
|
+
body = 'you are so bad!'
|
43
|
+
status = 400
|
35
44
|
when '/text'
|
36
45
|
headers['Content-Type'] = 'text/plain'
|
37
46
|
body = 'foo-bar and others'
|
@@ -43,11 +52,17 @@ def app
|
|
43
52
|
when '/redirect'
|
44
53
|
headers['Location'] = '/target'
|
45
54
|
status = 302
|
55
|
+
when '/moved'
|
56
|
+
headers['Location'] = '/target'
|
57
|
+
status = 301
|
46
58
|
when '/arg_error'
|
47
59
|
handle_exception(env) do
|
48
60
|
tester 234
|
49
61
|
end
|
50
62
|
status = 500
|
63
|
+
when '/error_code'
|
64
|
+
status = 500
|
65
|
+
body = "some error message"
|
51
66
|
when '/not_found'
|
52
67
|
status = 404
|
53
68
|
body = "<body>Not found</body>"
|
@@ -58,9 +73,18 @@ def app
|
|
58
73
|
}
|
59
74
|
end
|
60
75
|
|
76
|
+
describe "without assert-response" do
|
77
|
+
it "should raise no error" do
|
78
|
+
get '/error'
|
79
|
+
assert_equal 500, last_response.status
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
61
84
|
describe "assert-response" do
|
62
85
|
it "should check json" do
|
63
86
|
get '/json'
|
87
|
+
assert_response_body /ok/, :ok
|
64
88
|
assert_response_json /ok/
|
65
89
|
end
|
66
90
|
|
@@ -69,6 +93,32 @@ describe "assert-response" do
|
|
69
93
|
assert_response_html '<body>'
|
70
94
|
end
|
71
95
|
|
96
|
+
it "should check for status regex" do
|
97
|
+
get '/html'
|
98
|
+
assert_response_status /200/
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should check for json body content" do
|
102
|
+
get '/json'
|
103
|
+
assert_response_json do
|
104
|
+
assert_equal "ok", json["response"]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should check for json body content for a created ressource" do
|
109
|
+
get '/create_with_json'
|
110
|
+
assert_response_json :created do
|
111
|
+
assert_equal "new_id", json["id"]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should check for json body content without assert prefix" do
|
116
|
+
get '/create_with_json'
|
117
|
+
assert_response_json :created do
|
118
|
+
equal "new_id", json["id"]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
72
122
|
it "should check css" do
|
73
123
|
get '/css'
|
74
124
|
assert_response_css 'color'
|
@@ -92,6 +142,11 @@ describe "assert-response" do
|
|
92
142
|
assert_response_redirect '/target'
|
93
143
|
end
|
94
144
|
|
145
|
+
it "should check moved" do
|
146
|
+
get '/moved'
|
147
|
+
assert_response_moved '/target'
|
148
|
+
end
|
149
|
+
|
95
150
|
it "should not find missing pages" do
|
96
151
|
get '/settings'
|
97
152
|
assert_response_not_found
|
@@ -107,6 +162,12 @@ describe "assert-response" do
|
|
107
162
|
assert_response_raises ArgumentError
|
108
163
|
end
|
109
164
|
|
165
|
+
it "check server-error without a raised error" do
|
166
|
+
get '/error_code'
|
167
|
+
assert_response_error
|
168
|
+
assert_response_body "some error message", :error
|
169
|
+
end
|
170
|
+
|
110
171
|
it "should raise errors for some other sinatra errors" do
|
111
172
|
get '/error'
|
112
173
|
assert_raises RuntimeError do
|
@@ -133,3 +194,99 @@ describe "assert-response" do
|
|
133
194
|
assert_response_not_found_html "<body>Not found</body>"
|
134
195
|
end
|
135
196
|
end
|
197
|
+
|
198
|
+
describe "status tests" do
|
199
|
+
it "should check for ok status (20x) if asked to do, or if nil is passed to status" do
|
200
|
+
get '/html'
|
201
|
+
assert_response_ok
|
202
|
+
assert_response_status nil
|
203
|
+
assert_response_status 200
|
204
|
+
|
205
|
+
get '/create_with_json'
|
206
|
+
assert_response_ok
|
207
|
+
assert_response_status nil
|
208
|
+
assert_response_status 201
|
209
|
+
|
210
|
+
get '/not_found'
|
211
|
+
assert_raises AssertResponse::Status404 do
|
212
|
+
assert_response_ok
|
213
|
+
end
|
214
|
+
|
215
|
+
assert_raises AssertResponse::Status404 do
|
216
|
+
assert_response_status nil
|
217
|
+
end
|
218
|
+
|
219
|
+
assert_raises AssertResponse::Status404 do
|
220
|
+
assert_response_status 201
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
it "check for a named status if asked to do so" do
|
225
|
+
get '/create_with_json'
|
226
|
+
assert_response_created
|
227
|
+
assert_response_status :created
|
228
|
+
assert_response_status 201
|
229
|
+
|
230
|
+
get '/not_found'
|
231
|
+
end
|
232
|
+
|
233
|
+
it "check for a regexp status if asked to do so" do
|
234
|
+
get '/create_with_json'
|
235
|
+
assert_response_created
|
236
|
+
assert_response_status /20/
|
237
|
+
|
238
|
+
get '/html'
|
239
|
+
assert_response_status 200
|
240
|
+
assert_response_status /20/
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should raise an error if asked for a non 4xx/5xx code and a 4xx/5xx code is returned" do
|
244
|
+
|
245
|
+
{
|
246
|
+
'/error_code' => AssertResponse::HttpError,
|
247
|
+
'/error' => RuntimeError,
|
248
|
+
'/not_found' => AssertResponse::Status404
|
249
|
+
}.each do |url,error|
|
250
|
+
|
251
|
+
get url
|
252
|
+
|
253
|
+
assert_raises error do
|
254
|
+
assert_response_ok
|
255
|
+
end
|
256
|
+
|
257
|
+
assert_raises error do
|
258
|
+
assert_response_status nil
|
259
|
+
end
|
260
|
+
|
261
|
+
assert_raises error do
|
262
|
+
assert_response_created
|
263
|
+
end
|
264
|
+
|
265
|
+
assert_raises error do
|
266
|
+
assert_response_status :moved
|
267
|
+
end
|
268
|
+
|
269
|
+
assert_raises error do
|
270
|
+
assert_response_status /^3/
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should raise no error if asked for a 4xx/5xx code and a 4xx/5xx code is returned" do
|
277
|
+
|
278
|
+
get '/error_code'
|
279
|
+
|
280
|
+
assert_response_status 500
|
281
|
+
assert_response_status /^5/
|
282
|
+
assert_response_status :error
|
283
|
+
|
284
|
+
get '/not_found'
|
285
|
+
|
286
|
+
assert_response_status 404
|
287
|
+
assert_response_status /^4/
|
288
|
+
assert_response_status :not_found
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert-response
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack-test
|
16
|
-
requirement: &
|
16
|
+
requirement: &22354580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22354580
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
requirement: &22354100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *22354100
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: yard
|
27
|
-
requirement: &
|
38
|
+
requirement: &22353580 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *22353580
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: bundler
|
38
|
-
requirement: &
|
49
|
+
requirement: &22353100 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: 1.0.0
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *22353100
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: jeweler
|
49
|
-
requirement: &
|
60
|
+
requirement: &22352580 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: 1.5.2
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *22352580
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rcov
|
60
|
-
requirement: &
|
71
|
+
requirement: &22352100 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,21 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *22352100
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: rack-test
|
71
|
-
requirement: &
|
82
|
+
requirement: &22351620 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *22351620
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: json
|
93
|
+
requirement: &22351140 !ruby/object:Gem::Requirement
|
72
94
|
none: false
|
73
95
|
requirements:
|
74
96
|
- - ! '>='
|
@@ -76,7 +98,7 @@ dependencies:
|
|
76
98
|
version: '0'
|
77
99
|
type: :runtime
|
78
100
|
prerelease: false
|
79
|
-
version_requirements: *
|
101
|
+
version_requirements: *22351140
|
80
102
|
description:
|
81
103
|
email: ! 'Base64.decode64(''bGludXhAbWFyY3JlbmVhcm5zLmRl
|
82
104
|
|
@@ -111,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
133
|
version: '0'
|
112
134
|
segments:
|
113
135
|
- 0
|
114
|
-
hash:
|
136
|
+
hash: 2830934270081401981
|
115
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
138
|
none: false
|
117
139
|
requirements:
|