add fuzzy range options to cucumber tests

This commit is contained in:
Emil Tin
2012-08-31 08:10:55 +02:00
parent e0f51dd5e9
commit 62c12e7473
2 changed files with 64 additions and 41 deletions
+26 -1
View File
@@ -231,7 +231,32 @@ When /^I route I should get$/ do |table|
end
end
if row != got
ok = true
row.keys.each do |key|
if row[key].match /(.*)\s+~(.+)%$/
margin = 1 - $2.to_f*0.01
from = $1.to_f*margin
to = $1.to_f/margin
if (from..to).cover? got[key].to_f
got[key] = row[key]
else
ok = false
end
elsif row[key].match /(.*)\s+\+\-(.+)$/
margin = $2.to_f
from = $1.to_f-margin
to = $1.to_f+margin
if (from..to).cover? got[key].to_f
got[key] = row[key]
else
ok = false
end
else
ok = row[key] == got[key].to_f
end
end
unless ok
failed = { :attempt => 'route', :query => @query, :response => response }
log_fail row,got,[failed]
end