4
5
6
7
8
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
37
38
39
40
41
42
|
# File 'lib/rspec/swagger/routes_with_sample_values.rb', line 4
def test_sample_values_for_path_params_on_get_routes
@loader.documented_paths.each do |api|
if api =~ /\{.*\}/
if operation = @loader.operation(:GET, api)
["200", "403", "404"].each do |code|
api_with_values = api.clone
operation["parameters"].each do |param|
if sample_value = sample_value_from_param(param, code)
api_with_values = api_with_values.gsub("{#{param['name']}}", sample_value)
end
end
unless api_with_values.include?("{")
begin
get api_with_values
@formatter.format passed: last_response.status.to_i == code.to_i,
left_text: api_with_values,
right_text: "was <#{last_response.status}>"
@formatter.format passed: last_response.status.to_i == code.to_i,
left_text: api_with_values,
right_text: "#{code} <documented>"
rescue
@formatter.format passed: false,
left_text: api_with_values,
right_text: "<#{$!.message}>"
@formatter.format passed: false,
left_text: api_with_values,
right_text: "#{code} <documented>"
end
end
end
end
end
end
end
|