Skip to content

Instantly share code, notes, and snippets.

@tygern
Created August 26, 2015 13:13
Show Gist options
  • Save tygern/1c667b9dca8552b7e60c to your computer and use it in GitHub Desktop.
Save tygern/1c667b9dca8552b7e60c to your computer and use it in GitHub Desktop.
Testing External Services - ZippyEnvironment
class ZippyEnvironment
def initialize
@account_ids = []
yield self
ensure
clean_up
end
def create_account(data)
account = Zippy::Account.create(data)
if account.errors.empty?
@account_ids << account.id
else
raise "Failed to create: #{account.errors.inspect}"
end
account
end
private
def clean_up
delete_accounts
end
def delete_accounts
failed_deletions = []
@account_ids.each do |id|
success = Zippy::Account.delete(id)
failed_deletions << id unless success
end
if failed_deletions.present?
raise "Failed to delete: #{failed_deletions.inspect}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment