Class: Mimic::FakeHost::StubbedRequest
- Inherits:
-
Object
- Object
- Mimic::FakeHost::StubbedRequest
- Defined in:
- lib/mimic/fake_host.rb
Instance Attribute Summary collapse
-
#received ⇒ Object
Returns the value of attribute received.
Instance Method Summary collapse
- #build ⇒ Object
- #echo_request!(format = :json) ⇒ Object
-
#initialize(app, method, path) ⇒ StubbedRequest
constructor
A new instance of StubbedRequest.
- #matched_response ⇒ Object
- #matches?(request) ⇒ Boolean
- #response_for_request(request) ⇒ Object
- #returning(body, code = 200, headers = {}) ⇒ Object
- #to_hash ⇒ Object
- #unmatched_response ⇒ Object
- #with_query_parameters(params) ⇒ Object
Constructor Details
#initialize(app, method, path) ⇒ StubbedRequest
Returns a new instance of StubbedRequest.
149 150 151 152 153 154 155 156 157 |
# File 'lib/mimic/fake_host.rb', line 149 def initialize(app, method, path) @method, @path = method, path @code = 200 @headers = {} @params = {} @body = "" @app = app @received = false end |
Instance Attribute Details
#received ⇒ Object
Returns the value of attribute received.
147 148 149 |
# File 'lib/mimic/fake_host.rb', line 147 def received @received end |
Instance Method Details
#build ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/mimic/fake_host.rb', line 206 def build stub = self @app.send(@method.downcase, @path) do stub.received = true stub.response_for_request(request) end end |
#echo_request!(format = :json) ⇒ Object
178 179 180 |
# File 'lib/mimic/fake_host.rb', line 178 def echo_request!(format = :json) @echo_request_format = format end |
#matched_response ⇒ Object
190 191 192 |
# File 'lib/mimic/fake_host.rb', line 190 def matched_response [@code, @headers, @body] end |
#matches?(request) ⇒ Boolean
182 183 184 185 186 187 188 |
# File 'lib/mimic/fake_host.rb', line 182 def matches?(request) if @params.any? request.params == @params else true end end |
#response_for_request(request) ⇒ Object
198 199 200 201 202 203 204 |
# File 'lib/mimic/fake_host.rb', line 198 def response_for_request(request) if @echo_request_format @body = RequestEcho.new(request).to_s(@echo_request_format) end matches?(request) ? matched_response : unmatched_response end |
#returning(body, code = 200, headers = {}) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/mimic/fake_host.rb', line 164 def returning(body, code = 200, headers = {}) tap do @body = body @code = code @headers = headers end end |
#to_hash ⇒ Object
159 160 161 162 |
# File 'lib/mimic/fake_host.rb', line 159 def to_hash token = "#{@method} #{@path}" Digest::MD5.hexdigest(token) end |
#unmatched_response ⇒ Object
194 195 196 |
# File 'lib/mimic/fake_host.rb', line 194 def unmatched_response [404, {}, ""] end |
#with_query_parameters(params) ⇒ Object
172 173 174 175 176 |
# File 'lib/mimic/fake_host.rb', line 172 def with_query_parameters(params) tap do @params = params end end |