Class: ApiTester::Response
- Inherits:
-
Object
- Object
- ApiTester::Response
- Defined in:
- lib/api-tester/definition/response.rb
Overview
Class for defining expected responses
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
Instance Method Summary collapse
- #add_field(new_field) ⇒ Object
- #field_display(field) ⇒ Object
-
#initialize(status_code: 200) ⇒ Response
constructor
A new instance of Response.
- #to_s ⇒ Object
Constructor Details
#initialize(status_code: 200) ⇒ Response
Returns a new instance of Response.
8 9 10 11 |
# File 'lib/api-tester/definition/response.rb', line 8 def initialize(status_code: 200) self.code = status_code self.body = [] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/api-tester/definition/response.rb', line 6 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/api-tester/definition/response.rb', line 6 def code @code end |
Instance Method Details
#add_field(new_field) ⇒ Object
13 14 15 16 |
# File 'lib/api-tester/definition/response.rb', line 13 def add_field(new_field) body << new_field self end |
#field_display(field) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/api-tester/definition/response.rb', line 30 def field_display(field) des = field.display_class if field.subfields? des = {} field.fields.map do |f| if f.has_key des[f.name] = field_display f else des = field_display f end end des.to_json end des end |
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/api-tester/definition/response.rb', line 18 def to_s des = {} body.map do |f| if f.has_key des[f.name] = field_display f else des = field_display f end end des.to_json end |