Skip to content

Commit e496d0f

Browse files
committed
Fix failing tests on Ruby 2.5
There seems to be some issue with ordering when testing the swagger results.
1 parent ec5dc27 commit e496d0f

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

spec/spec_helper.rb

+11-13
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,26 @@ def compatible_request(method, action, hash = {})
6161

6262
def deep_match?(actual, expected, breadcrumb=[])
6363
num = 0
64-
for pdesc in expected do
64+
expected.each do |pdesc|
6565
if pdesc.is_a? Symbol
66-
return false unless fields_match?(actual.params_ordered[num], pdesc, breadcrumb)
66+
return false unless matching_param(actual.params_ordered, pdesc, breadcrumb)
6767
elsif pdesc.is_a? Hash
68-
return false unless fields_match?(actual.params_ordered[num], pdesc.keys[0], breadcrumb)
69-
return false unless deep_match?(actual.params_ordered[num].validator, pdesc.values[0], breadcrumb + [pdesc.keys[0]])
68+
param = matching_param(actual.params_ordered, pdesc.keys[0], breadcrumb)
69+
return false unless param
70+
return false unless deep_match?(param.validator, pdesc.values[0], breadcrumb + [pdesc.keys[0]])
7071
end
7172
num+=1
7273
end
7374
@fail_message = "expected property count#{breadcrumb == [] ? '' : ' of ' + (breadcrumb).join('.')} (#{actual.params_ordered.count}) to be #{num}"
7475
actual.params_ordered.count == num
7576
end
7677

77-
def fields_match?(param, expected_name, breadcrumb)
78-
return false unless have_field?(param, expected_name, breadcrumb)
79-
@fail_message = "expected #{(breadcrumb + [param.name]).join('.')} to eq #{(breadcrumb + [expected_name]).join('.')}"
80-
param.name.to_s == expected_name.to_s
81-
end
82-
83-
def have_field?(field, expected_name, breadcrumb)
84-
@fail_message = "expected property #{(breadcrumb+[expected_name]).join('.')}"
85-
!field.nil?
78+
def matching_param(params, expected_name, breadcrumb)
79+
param = params.find { |p| p.name.to_s == expected_name.to_s }
80+
unless param
81+
@fail_message = "expected [#{ params.map(&:name).join(', ') }] to include #{(breadcrumb + [expected_name]).join('.')}"
82+
end
83+
param
8684
end
8785

8886
failure_message do |actual|

0 commit comments

Comments
 (0)