Skip to content

Instantly share code, notes, and snippets.

@chad
Created June 24, 2011 15:56
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 chad/1045080 to your computer and use it in GitHub Desktop.
Save chad/1045080 to your computer and use it in GitHub Desktop.
def assert_difference(string, expected_difference = 1, &block)
before = eval(string, block.binding)
block.call
after = eval(string, block.binding)
fail "Expected a difference of #{expected_difference}" unless after - before == expected_difference
end
a = 1
assert_difference("a", 1) do
a += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment