Skip to content

Commit 1091701

Browse files
committed
[API] Test Runner: update compare string matcher for floats
1 parent f17eb5e commit 1091701

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

elasticsearch-api/api-spec-testing/rspec_matchers.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ def compare_string(expected, actual_value, test, response)
243243
/#{parsed.tr("/", "")}/ =~ actual_value
244244
elsif !!(expected.match?(/^-?[0-9]{1}\.[0-9]+E[0-9]+/))
245245
# When the value in the yaml test is a big number, the format is
246-
# different from what Ruby uses, so we transform X.XXXXEXX to X.XXXXXe+XX
247-
# to be able to compare the values
248-
actual_value.to_s == expected.gsub('E', 'e+') || actual_value == expected
246+
# different from what Ruby uses, so we try different options:
247+
actual_value.to_s == expected.gsub('E', 'e+') || # transform X.XXXXEXX to X.XXXXXe+XX to compare thme
248+
actual_value == expected || # compare the actual values
249+
expected.to_f.to_s == actual_value.to_f.to_s # transform both to Float and compare them
249250
elsif expected == '' && actual_value != ''
250251
actual_value == response
251252
else

0 commit comments

Comments
 (0)