Skip to content

Commit 040c4d8

Browse files
committed
Fix intermittent swagger test failures
In some Ruby implementations, we couldn't rely on specific order in the hash. The new matcher implementation doesn't rely on the order.
1 parent f108bb5 commit 040c4d8

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

spec/lib/swagger/swagger_dsl_spec.rb

+20-10
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,28 @@ def swagger_param_by_name(param_name, path, method='get')
7373
end
7474

7575
def deep_match?(actual, expected, breadcrumb=[])
76-
num = 0
77-
for pdesc in expected do
78-
if pdesc.is_a? Symbol
79-
return false unless fields_match?(actual.params_ordered[num], pdesc, breadcrumb)
80-
elsif pdesc.is_a? Hash
81-
return false unless fields_match?(actual.params_ordered[num], pdesc.keys[0], breadcrumb)
82-
return false unless deep_match?(actual.params_ordered[num].validator, pdesc.values[0], breadcrumb + [pdesc.keys[0]])
76+
pending_params = actual.params_ordered.dup
77+
expected.each do |expected_param|
78+
expected_param_name = expected_param.is_a?(Hash) ? expected_param.keys.first : expected_param
79+
actual_param = pending_params.find { |param| param.name.to_s == expected_param_name.to_s }
80+
unless actual_param
81+
@fail_message = "Couldn't find #{expected_param_name.inspect} among #{pending_params.map(&:name)} in #{breadcrumb.join('.')}"
82+
return false
83+
else
84+
pending_params.delete_if { |p| p.object_id == actual_param.object_id }
8385
end
84-
num+=1
86+
87+
return false unless fields_match?(actual_param, expected_param_name, breadcrumb)
88+
if expected_param.is_a? Hash
89+
return false unless deep_match?(actual_param.validator, expected_param.values[0], breadcrumb + [expected_param.keys.first])
90+
end
91+
end
92+
93+
unless pending_params.empty?
94+
@fail_message = "Unexpected properties #{pending_params.map(&:name)} in #{breadcrumb.join('.')}"
95+
return false
8596
end
86-
@fail_message = "expected property count#{breadcrumb == [] ? '' : ' of ' + (breadcrumb).join('.')} (#{actual.params_ordered.count}) to be #{num}"
87-
actual.params_ordered.count == num
97+
true
8898
end
8999

90100
def fields_match?(param, expected_name, breadcrumb)

0 commit comments

Comments
 (0)