9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/camille/testing.rb', line 9
def data
controller_path = request && request.path_parameters[:controller]
action = request && request.path_parameters[:action]
unless controller_path && action
raise Camille::Testing::MissingEndpointError,
"No camille endpoint for this response (request did not match a controller action)."
end
controller_class_name = "#{controller_path.camelize}Controller"
schema = Camille::Loader.controller_name_to_schema_map[controller_class_name]
endpoint = schema && schema.endpoints[action.to_sym]
unless endpoint
raise Camille::Testing::MissingEndpointError,
"No camille endpoint for #{controller_class_name}##{action}."
end
result = endpoint.response_type.check_params(parsed_body)
if result.type_error?
io = StringIO.new
Camille::TypeErrorPrinter.new(result).print(io)
raise Camille::Testing::ResponseTypeError,
"\nResponse type check failed.\n#{io.string}"
end
deep_indifferent(result.value)
end
|