Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created March 14, 2009 10:49
Show Gist options
  • Select an option

  • Save methodmissing/79044 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/79044 to your computer and use it in GitHub Desktop.
def test_should_rollback_any_changes_if_an_exception_occurred_while_saving
before = [@pirate.catchphrase, @pirate.ship.name]
@pirate.catchphrase = 'Arr'
@pirate.ship.name = 'The Vile Insanity'
# Stub the save method of the @pirate.ship instance to raise an exception
class << @pirate.ship
def save(*args)
super
raise 'Oh noes!'
end
end
assert_raise(RuntimeError) { assert !@pirate.save }
assert_equal before, [@pirate.reload.catchphrase, @pirate.ship.name]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment