lib/fitting/matchers/response_matcher.rb in fitting-1.5.0 vs lib/fitting/matchers/response_matcher.rb in fitting-1.6.0
- old
+ new
@@ -1,19 +1,17 @@
require 'fitting/response'
-require 'fitting/storage/responses'
require 'fitting/storage/documentation'
module Fitting
module Matchers
class Response
def matches?(response)
@response = Fitting::Response.new(
response,
Fitting::Storage::Documentation.tomogram
)
- Fitting::Storage::Responses.push(@response)
- @response.valid?
+ @response.fully_validates.valid?
end
def ===(other)
matches?(other)
end
@@ -22,19 +20,51 @@
unless @response.documented?
return "response not documented\n"\
"got: #{@response.real_request_with_status}"
end
- unless @response.valid?
+ unless @response.fully_validates.valid?
"response does not conform to json-schema\n"\
"schemas: \n#{@response.expected}\n\n"\
"got: #{@response.got}\n\n"\
- "errors: \n#{@response.diff}\n"
+ "errors: \n#{@response.fully_validates}\n"
end
end
end
+ class StrictResponse
+ def matches?(response)
+ @response = Fitting::Response.new(
+ response,
+ Fitting::Storage::Documentation.tomogram
+ )
+ @response.strict_fully_validates.valid?
+ end
+
+ def ===(other)
+ matches?(other)
+ end
+
+ def failure_message
+ unless @response.documented?
+ return "response not documented\n"\
+ "got: #{@response.real_request_with_status}"
+ end
+
+ unless @response.strict_fully_validates.valid?
+ "response does not conform to json-schema\n"\
+ "schemas: \n#{@response.expected}\n\n"\
+ "got: #{@response.got}\n\n"\
+ "errors: \n#{@response.strict_fully_validates}\n"
+ end
+ end
+ end
+
def match_response
Response.new
+ end
+
+ def strict_match_response
+ StrictResponse.new
end
end
end