Skip to content

Instantly share code, notes, and snippets.

@trak3r
Created June 22, 2009 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trak3r/134143 to your computer and use it in GitHub Desktop.
Save trak3r/134143 to your computer and use it in GitHub Desktop.
assert_close_enough
def assert_close_enough(target, actual, message = nil)
lower = (0.9 * target.to_f).floor
upper = (1.1 * target.to_f).ceil
full_message = build_message(message,
"<?-?> expected but was\n<?>.\n", lower, upper, actual)
assert_block(full_message) { actual >= lower and actual <= upper }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment