Class: Peck::Should::ResponseRequirement
- Inherits:
-
Proxy
- Object
- Proxy
- Peck::Should::ResponseRequirement
- Defined in:
- lib/peck_on_rails/assertions.rb
Direct Known Subclasses
Constant Summary collapse
- SUPPORTED_VERBS =
[:get, :post, :put, :delete, :options]
Instance Attribute Summary collapse
-
#allowed_exceptions ⇒ Object
Returns the value of attribute allowed_exceptions.
-
#expected ⇒ Object
Returns the value of attribute expected.
-
#method ⇒ Object
Returns the value of attribute method.
Class Method Summary collapse
Instance Method Summary collapse
- #define_specification(verb, action, params = {}) ⇒ Object
- #method_missing(method, *attributes, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *attributes, &block) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/peck_on_rails/assertions.rb', line 38 def method_missing(method, *attributes, &block) verb = method.to_sym if self.class.supported_verbs.include?(verb) define_specification(verb, *attributes) else super end end |
Instance Attribute Details
#allowed_exceptions ⇒ Object
Returns the value of attribute allowed_exceptions.
6 7 8 |
# File 'lib/peck_on_rails/assertions.rb', line 6 def allowed_exceptions @allowed_exceptions end |
#expected ⇒ Object
Returns the value of attribute expected.
6 7 8 |
# File 'lib/peck_on_rails/assertions.rb', line 6 def expected @expected end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/peck_on_rails/assertions.rb', line 6 def method @method end |
Class Method Details
.supported_verbs ⇒ Object
47 48 49 |
# File 'lib/peck_on_rails/assertions.rb', line 47 def self.supported_verbs SUPPORTED_VERBS end |
Instance Method Details
#define_specification(verb, action, params = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/peck_on_rails/assertions.rb', line 8 def define_specification(verb, action, params={}) _method = self.method _negated = self.negated _expected = self.expected _allowed_exceptions = self.allowed_exceptions context.it(description(verb, action, params)) do begin immediate_values = immediate_values(params) if immediate_values.present? send(verb, action, immediate_values) else send(verb, action) end rescue => raised_exception if _allowed_exceptions _allowed_exceptions.any? { |exception| raised_exception.should.be.kind_of(exception) } true.should.eql(true) # Force the expectations counter else raise end else if _negated send(_method).should.not == _expected else send(_method).should.eql(_expected) end end end end |