|
6 | 6 | require 'rest_yaml_tests_helper'
|
7 | 7 |
|
8 | 8 | describe 'Rest API YAML tests' do
|
9 |
| - |
| 9 | + # Traverse YAML files and create TestFile object: |
10 | 10 | REST_API_YAML_FILES.each do |file|
|
11 |
| - |
12 | 11 | test_file = Elasticsearch::RestAPIYAMLTests::TestFile.new(file, REST_API_YAML_SKIP_FEATURES)
|
13 | 12 |
|
14 | 13 | context "#{file.gsub("#{YAML_FILES_DIRECTORY}/", '')}" do
|
15 |
| - |
16 | 14 | test_file.tests.each do |test|
|
17 | 15 |
|
18 | 16 | context "#{test.description}" do
|
19 |
| - |
20 | 17 | if test.skip_test?(ADMIN_CLIENT)
|
21 | 18 | skip 'Test contains feature(s) not yet supported or version is not satisfied'
|
22 |
| - |
23 | 19 | else
|
24 |
| - |
25 | 20 | let(:client) do
|
26 | 21 | DEFAULT_CLIENT
|
27 | 22 | end
|
28 | 23 |
|
29 | 24 | # Runs once before each test in a test file
|
30 | 25 | before(:all) do
|
31 |
| - # Runs once before each test in a test file |
32 | 26 | Elasticsearch::RestAPIYAMLTests::TestFile.clear_data(ADMIN_CLIENT)
|
33 | 27 | test_file.setup(ADMIN_CLIENT)
|
34 | 28 | end
|
|
39 | 33 | end
|
40 | 34 |
|
41 | 35 | test.task_groups.each do |task_group|
|
42 |
| - |
43 | 36 | before do
|
44 | 37 | task_group.run(client)
|
45 | 38 | end
|
46 | 39 |
|
47 | 40 | # 'catch' is in the task group definition
|
48 | 41 | if task_group.catch_exception?
|
49 |
| - |
50 | 42 | it 'sends the request and throws the expected error' do
|
51 | 43 | expect(task_group.exception).to match_error(task_group.expected_exception_message)
|
52 | 44 | end
|
53 | 45 |
|
54 | 46 | # 'match' on error description is in the task group definition
|
55 | 47 | if task_group.has_match_clauses?
|
56 |
| - |
57 | 48 | task_group.match_clauses.each do |match|
|
58 | 49 | it 'contains the expected error in the request response' do
|
59 | 50 | expect(task_group.exception.message).to match(Regexp.new(Regexp.escape(match['match'].values.first.to_s)))
|
|
64 | 55 |
|
65 | 56 | # 'match' is in the task group definition
|
66 | 57 | if task_group.has_match_clauses?
|
67 |
| - |
68 | 58 | task_group.match_clauses.each do |match|
|
69 | 59 | it "has the expected value (#{match['match'].values.join(',')}) in the response field (#{match['match'].keys.join(',')})" do
|
70 | 60 | expect(task_group.response).to match_response(match['match'], test)
|
|
74 | 64 |
|
75 | 65 | # 'length' is in the task group definition
|
76 | 66 | if task_group.has_length_match_clauses?
|
77 |
| - |
78 | 67 | task_group.length_match_clauses.each do |match|
|
79 | 68 | it "the '#{match['length'].keys.join(',')}' field have the expected length" do
|
80 | 69 | expect(task_group.response).to match_response_field_length(match['length'], test)
|
|
84 | 73 |
|
85 | 74 | # 'is_true' is in the task group definition
|
86 | 75 | if task_group.has_true_clauses?
|
87 |
| - |
88 | 76 | task_group.true_clauses.each do |match|
|
89 | 77 | it "sends the request and the '#{match['is_true']}' field is set to true" do
|
90 | 78 | expect(task_group.response).to match_true_field(match['is_true'], test)
|
|
94 | 82 |
|
95 | 83 | # 'is_false' is in the task group definition
|
96 | 84 | if task_group.has_false_clauses?
|
97 |
| - |
98 | 85 | task_group.false_clauses.each do |match|
|
99 | 86 | it "sends the request and the '#{match['is_false']}' field is set to true" do
|
100 | 87 | expect(task_group.response).to match_false_field(match['is_false'], test)
|
|
104 | 91 |
|
105 | 92 | # 'gte' is in the task group definition
|
106 | 93 | if task_group.has_gte_clauses?
|
107 |
| - |
108 | 94 | task_group.gte_clauses.each do |match|
|
109 | 95 | it "sends the request and the '#{match['gte']}' field is greater than or equal to the expected value" do
|
110 | 96 | expect(task_group.response).to match_gte_field(match['gte'], test)
|
|
114 | 100 |
|
115 | 101 | # 'gt' is in the task group definition
|
116 | 102 | if task_group.has_gt_clauses?
|
117 |
| - |
118 | 103 | task_group.gt_clauses.each do |match|
|
119 | 104 | it "sends the request and the '#{match['gt']}' field is greater than the expected value" do
|
120 | 105 | expect(task_group.response).to match_gt_field(match['gt'], test)
|
|
124 | 109 |
|
125 | 110 | # 'lte' is in the task group definition
|
126 | 111 | if task_group.has_lte_clauses?
|
127 |
| - |
128 | 112 | task_group.lte_clauses.each do |match|
|
129 | 113 | it "sends the request and the '#{match['lte']}' field is less than or equal to the expected value" do
|
130 | 114 | expect(task_group.response).to match_lte_field(match['lte'], test)
|
|
134 | 118 |
|
135 | 119 | # 'lt' is in the task group definition
|
136 | 120 | if task_group.has_lt_clauses?
|
137 |
| - |
138 | 121 | task_group.lt_clauses.each do |match|
|
139 | 122 | it "sends the request and the '#{match['lt']}' field is less than the expected value" do
|
140 | 123 | expect(task_group.response).to match_lt_field(match['lt'], test)
|
|
0 commit comments