Skip to content

Instantly share code, notes, and snippets.

@moiristo
Created November 11, 2010 13:07
Show Gist options
  • Save moiristo/672465 to your computer and use it in GitHub Desktop.
Save moiristo/672465 to your computer and use it in GitHub Desktop.
Test helper method to perform multiple assert_difference calls easily.
# Example
assert_differences 'Initiative.count' => 1, 'Role.count' => -1, 'Phase.count' => 0 do
@initiative.to_template!
end
def assert_differences(collection = {}, &block)
yield and return if collection.empty?
collection.shift.tap do |diff|
assert_differences(collection){ assert_difference(diff.first, diff.last, &block) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment