Class: FakeService::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- FakeService::Server
- Defined in:
- lib/fake_service/server.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#equal_json_bodies?(expected_body, body) ⇒ Boolean
Checks for bodies equality.
-
#right_header?(expected, actual) ⇒ Boolean
Checks for request comes with right header.
Class Method Details
.define_action!(expected_request, expected_response) ⇒ Object
define action.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fake_service/server.rb', line 26 def self.define_action!(expected_request, expected_response) action = expected_request["method"].downcase url = expected_request["full_path"] send(action, url, provides: :json) do pass unless right_header?(expected_request["headers"], request.env) pass unless equal_json_bodies?(expected_request["body"], request.body.read) headers expected_response["headers"] status expected_response["code"] expected_response["body"] end end |
Instance Method Details
#equal_json_bodies?(expected_body, body) ⇒ Boolean
Checks for bodies equality. json bodies keys can have different orders.
14 15 16 |
# File 'lib/fake_service/server.rb', line 14 def equal_json_bodies?(expected_body, body) JSON.parse(expected_body) == JSON.parse(body) end |
#right_header?(expected, actual) ⇒ Boolean
Checks for request comes with right header.
19 20 21 22 23 |
# File 'lib/fake_service/server.rb', line 19 def right_header?(expected, actual) expected.inject(true) do |memo, (k, v)| memo && v == actual[k] end end |