Module: Poisol::RequestMatcher
- Extended by:
- RequestMatcher
- Included in:
- RequestMatcher
- Defined in:
- lib/poisol/stub_mapper/request_matcher.rb
Instance Method Summary collapse
- #body_matches?(actual_req, stub_req) ⇒ Boolean
- #load_as_json(input) ⇒ Object
- #matches?(actual_req, stub_req) ⇒ Boolean
- #matching_array(actuals, expected) ⇒ Object
- #matching_hashes?(actuals, expected) ⇒ Boolean
- #query_matches?(actual_req, stub_req) ⇒ Boolean
- #type_matches?(actual_req, stub_req) ⇒ Boolean
- #url_macthes?(actual_req, stub_req) ⇒ Boolean
Instance Method Details
#body_matches?(actual_req, stub_req) ⇒ Boolean
28 29 30 31 32 33 34 35 36 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 28 def body_matches? actual_req,stub_req return true if actual_req.body == stub_req.body actual_req_body = load_as_json actual_req.body stub_req_body = load_as_json stub_req.body return false unless actual_req_body.class == stub_req_body.class return true if actual_req_body == stub_req_body return matching_hashes? actual_req_body,stub_req_body if actual_req_body.is_a?(Hash) return matching_array? actual_req_body,stub_req_body if actual_req_body.is_a?(Array) end |
#load_as_json(input) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 38 def load_as_json input begin return Parse.json_to_hash input rescue return input end end |
#matches?(actual_req, stub_req) ⇒ Boolean
5 6 7 8 9 10 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 5 def matches? actual_req,stub_req type_matches?(actual_req,stub_req) && url_macthes?(actual_req,stub_req) && query_matches?(actual_req,stub_req) && body_matches?(actual_req,stub_req) end |
#matching_array(actuals, expected) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 61 def matching_array actuals,expected return false unless actuals.size == expected.size return actuals.sort == expected.sort unless actual[0].is_a(Hash) expect = expected.clone actuals.each do |actual| match = expect.detect {|expected| matching_hashes? actual,expect} return false if match.blank? end end |
#matching_hashes?(actuals, expected) ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 47 def matching_hashes?(actuals, expected) return false unless actuals.keys.sort == expected.keys.sort actuals.each do |key, actual| expect = expected[key] if actual.is_a?(Hash) && expect.is_a?(Hash) return false unless matching_hashes?(actual, expect) else return false unless expect === actual end end true end |
#query_matches?(actual_req, stub_req) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 20 def query_matches? actual_req,stub_req return true if actual_req.query==stub_req.query return false if (actual_req.query.blank? || stub_req.query.blank?) actual_query = CGI::parse(actual_req.query) stub_query = CGI::parse(stub_req.query) return matching_hashes? actual_query,stub_query end |
#type_matches?(actual_req, stub_req) ⇒ Boolean
12 13 14 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 12 def type_matches? actual_req,stub_req actual_req.type == stub_req.type end |
#url_macthes?(actual_req, stub_req) ⇒ Boolean
16 17 18 |
# File 'lib/poisol/stub_mapper/request_matcher.rb', line 16 def url_macthes? actual_req,stub_req actual_req.url == stub_req.url end |