peck-on-rails 0.1.1 → 0.1.2
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/lib/peck_on_rails.rb +30 -7
- metadata +1 -1
data/lib/peck_on_rails.rb
CHANGED
@@ -254,14 +254,29 @@ class Peck
|
|
254
254
|
class ResponseRequirement < Peck::Should::Proxy
|
255
255
|
SUPPORTED_VERBS = [:get, :post, :put, :delete, :options]
|
256
256
|
|
257
|
-
attr_accessor :method, :expected
|
257
|
+
attr_accessor :method, :exception, :expected
|
258
258
|
|
259
259
|
def define_specification(verb, action, params={})
|
260
260
|
_method = self.method
|
261
|
+
_negated = self.negated
|
261
262
|
_expected = self.expected
|
263
|
+
_exception = self.exception
|
262
264
|
context.it(description(verb, action, params)) do
|
263
|
-
|
264
|
-
|
265
|
+
begin
|
266
|
+
send(verb, action, immediate_values(params))
|
267
|
+
rescue => raised_exception
|
268
|
+
if _negated
|
269
|
+
raised_exception.should.be.kind_of(_exception)
|
270
|
+
else
|
271
|
+
raised_exception.should.not.be.kind_of(_exception)
|
272
|
+
end
|
273
|
+
else
|
274
|
+
if _negated
|
275
|
+
send(_method).should.not == _expected
|
276
|
+
else
|
277
|
+
send(_method).should == _expected
|
278
|
+
end
|
279
|
+
end
|
265
280
|
end
|
266
281
|
end
|
267
282
|
|
@@ -300,10 +315,12 @@ class Peck
|
|
300
315
|
end
|
301
316
|
|
302
317
|
class Response < ResponseRequirement
|
318
|
+
attr_accessor :verb_description
|
319
|
+
|
303
320
|
def description(verb, action, params={})
|
304
321
|
description = ["should"]
|
305
322
|
description << "not" if (negated == false)
|
306
|
-
description << "
|
323
|
+
description << "#{verb_description} `#{action}'"
|
307
324
|
description << "#{params.inspect}" unless params.blank?
|
308
325
|
description.join(' ')
|
309
326
|
end
|
@@ -328,7 +345,7 @@ class Peck
|
|
328
345
|
|
329
346
|
def allow
|
330
347
|
requirement = Disallow.new(context)
|
331
|
-
requirement.negated =
|
348
|
+
requirement.negated = @negated
|
332
349
|
requirement.method = :allowed?
|
333
350
|
requirement.expected = true
|
334
351
|
requirement
|
@@ -336,9 +353,15 @@ class Peck
|
|
336
353
|
|
337
354
|
def find
|
338
355
|
requirement = Response.new(context)
|
339
|
-
requirement.negated =
|
356
|
+
requirement.negated = @negated
|
357
|
+
requirement.verb_description = 'find'
|
340
358
|
requirement.method = :status
|
341
|
-
|
359
|
+
if @negated
|
360
|
+
requirement.expected = :not_found
|
361
|
+
requirement.exception = ActiveRecord::RecordNotFound
|
362
|
+
else
|
363
|
+
requirement.expected = :ok
|
364
|
+
end
|
342
365
|
requirement
|
343
366
|
end
|
344
367
|
end
|