Class: MockServer::Model::Expectation
- Inherits:
-
Object
- Object
- MockServer::Model::Expectation
- Includes:
- UtilityMethods
- Defined in:
- lib/mockserver/model/expectation.rb
Overview
Expectation model
Instance Attribute Summary collapse
-
#times ⇒ Object
Returns the value of attribute times.
Instance Method Summary collapse
-
#forward {|the| ... } ⇒ Expectation
Method to setup the request on the expectation object.
-
#forward=(forward) ⇒ Object
Setter for forward.
-
#populate_from_payload(payload) ⇒ Object
Creates an expectation from a hash.
-
#request {|the| ... } ⇒ Expectation
Method to setup the request on the expectation object.
-
#request=(request) ⇒ Object
Setter for request.
-
#response {|the| ... } ⇒ Expectation
Method to setup the response on the expectation object.
-
#response=(response) ⇒ Object
Setter for response.
-
#to_hash ⇒ Hash
Convert to hash.
-
#to_json(*p) ⇒ String
Override to_json method.
Methods included from UtilityMethods
#camelize, #camelized_hash, #parse_string_to_json, #symbolize_keys
Instance Attribute Details
#times ⇒ Object
Returns the value of attribute times.
26 27 28 |
# File 'lib/mockserver/model/expectation.rb', line 26 def times @times end |
Instance Method Details
#forward {|the| ... } ⇒ Expectation
Method to setup the request on the expectation object
69 70 71 72 73 74 75 |
# File 'lib/mockserver/model/expectation.rb', line 69 def forward(&_) if block_given? @forward ||= Forward.new yield @forward end @forward end |
#forward=(forward) ⇒ Object
Setter for forward
91 92 93 |
# File 'lib/mockserver/model/expectation.rb', line 91 def forward=(forward) @forward = Forward.new(forward) end |
#populate_from_payload(payload) ⇒ Object
Creates an expectation from a hash
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mockserver/model/expectation.rb', line 30 def populate_from_payload(payload) @request = payload[MockServer::HTTP_REQUEST] @request = Request.new(symbolize_keys(@request)) if @request @response = payload[MockServer::HTTP_RESPONSE] @response = Response.new(symbolize_keys(@response)) if @response @forward = payload[MockServer::HTTP_FORWARD] @forward = Forward.new(symbolize_keys(@forward)) if @forward @times = payload[MockServer::HTTP_TIMES] @times = Times.new(symbolize_keys(@times)) if @times end |
#request {|the| ... } ⇒ Expectation
Method to setup the request on the expectation object
47 48 49 50 51 52 53 |
# File 'lib/mockserver/model/expectation.rb', line 47 def request(&_) if block_given? @request ||= Request.new yield @request end @request end |
#request=(request) ⇒ Object
Setter for request
79 80 81 |
# File 'lib/mockserver/model/expectation.rb', line 79 def request=(request) @request = Request.new(request) end |
#response {|the| ... } ⇒ Expectation
Method to setup the response on the expectation object
58 59 60 61 62 63 64 |
# File 'lib/mockserver/model/expectation.rb', line 58 def response(&_) if block_given? @response ||= Response.new yield @response end @response end |
#response=(response) ⇒ Object
Setter for response
85 86 87 |
# File 'lib/mockserver/model/expectation.rb', line 85 def response=(response) @response = Response.new(response) end |
#to_hash ⇒ Hash
Convert to hash
103 104 105 106 107 108 109 110 |
# File 'lib/mockserver/model/expectation.rb', line 103 def to_hash { MockServer::HTTP_REQUEST => @request, MockServer::HTTP_RESPONSE => @response, MockServer::HTTP_FORWARD => @forward, MockServer::HTTP_TIMES => @times } end |
#to_json(*p) ⇒ String
Override to_json method
97 98 99 |
# File 'lib/mockserver/model/expectation.rb', line 97 def to_json(*p) to_hash.to_json(*p) end |